Skip to content

Commit

Permalink
Merge branch 'develop' into TimothyDLewis/1195/wipe-everything-script…
Browse files Browse the repository at this point in the history
…-fails-foreign-key-constraints
  • Loading branch information
TimothyDLewis authored Oct 3, 2023
2 parents 5b23c35 + 3cbe90f commit 329a07a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/views/users/edit_profile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

<div class="grid--cell is-4 is-12-sm form-group">
<%= f.label :discord, class: 'form-element' %>
<span class="form-caption">Your Discord user tag, in the format <code>username#1234</code>.</span>
<span class="form-caption">Your Discord user tag, <code>username</code> or <code>username#1234</code>.</span>
<%= f.text_field :discord, class: 'form-element', autocomplete: 'off', placeholder: 'username#1234' %>
</div>
</div>
Expand Down Expand Up @@ -102,4 +102,4 @@
<%= submit_tag 'Claim Content', name: nil, class: 'button is-outlined' %>
<% end %>
</div>
<% end %>
<% end %>
30 changes: 27 additions & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
processed = ERB.new(File.read(f)).result(binding)
data = YAML.load(processed)
created = 0
errored = 0
skipped = 0
updated = 0
data.each do |seed|
Expand All @@ -39,20 +40,43 @@
puts "Running full Posts update..."

seed['body'] = ApplicationController.helpers.render_markdown(seed['body_markdown'])

system_usr = User.find(-1)

Community.all.each do |c|
RequestContext.community = c
post = Post.find_by doc_slug: seed['doc_slug']
if post.present? && PostHistory.where(post: post)
.where.not(post_history_type:
PostHistoryType.find_by(name: 'initial_revision'))
.count.zero?

# post exists, still original version: update post
post.update(seed.merge('community_id' => c.id))

no_initial = PostHistory.where(post: post)
.where(post_history_type: PostHistoryType.find_by(name: 'initial_revision'))
.count.zero?

if no_initial
puts "[#{c.name}:#{seed['doc_slug']}] missing initial revision, creating..."
PostHistory.initial_revision(post, system_usr)
end

updated += 1
elsif post.nil?
# post doesn't exist: create post
Post.create seed.merge('community_id' => c.id)
created += 1
status = Post.create seed.merge('community_id' => c.id, 'user' => system_usr)

if status.errors.size
status.errors.full_messages.each do |msg|
puts "[#{c.name}:#{seed['doc_slug']}] invalid: #{msg}"
end

errored += 1
else
created += 1
end
else
# post exists, versions diverged: skip
skipped += 1
Expand Down Expand Up @@ -92,7 +116,7 @@
end
end
unless Rails.env.test?
puts "#{type}: Created #{created}, #{updated > 0 ? "updated #{updated}, " : ''}skipped #{skipped}"
puts "#{type}: Errored #{errored}, Created #{created}, #{updated > 0 ? "updated #{updated}, " : ''}skipped #{skipped}"
end
rescue StandardError => e
puts "Got error #{e}. Continuing..."
Expand Down

0 comments on commit 329a07a

Please sign in to comment.