Browse Source

Implement initial db seed

pull/8/head
Angel Aviel Domaoan 4 years ago committed by Angel Aviel Domaoan
parent
commit
2a2e02679c
  1. 2
      Gemfile
  2. 3
      Gemfile.lock
  3. 2
      db/migrate/20220120043115_create_annomarks.rb
  4. 66
      db/seeds.rb

2
Gemfile

@ -121,3 +121,5 @@ group :development do
gem "bcrypt_pbkdf", "~> 1.1"
gem "ed25519", "~> 1.3"
end
gem "faker", "~> 2.19"

3
Gemfile.lock

@ -166,6 +166,8 @@ GEM
warden (~> 1.2.3)
ed25519 (1.3.0)
erubi (1.10.0)
faker (2.19.0)
i18n (>= 1.6, < 2)
faraday (1.9.3)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
@ -463,6 +465,7 @@ DEPENDENCIES
ckeditor!
devise (>= 4.7.1)
ed25519 (~> 1.3)
faker (~> 2.19)
figaro
foreman
jbuilder (~> 2.7)

2
db/migrate/20220120043115_create_annomarks.rb

@ -8,6 +8,6 @@ class CreateAnnomarks < ActiveRecord::Migration[6.1]
t.timestamps
end
add_index :annomarks, %i[name code], uniquness: true
add_index :annomarks, %i[name code], unique: true
end
end

66
db/seeds.rb

@ -8,33 +8,49 @@
if Rails.env.development?
subjects = [
"Civil Law",
"Commercial Law (or Mercantile Law)",
"Labor Law",
"Legal and Judicial Ethics",
"Remedial Law",
"Taxation Law",
"Political Law",
"Criminal Law"
].freeze
subjects.each { |name| Cdao::Subject.create(name: name, ancestry: nil) } if Cdao::Subject.count.zero?
annomarks = {
"A" => "Affirmed",
"C" => "Cited",
"D" => "Distinguished",
"F" => "Footnote",
"I" => "Illustrative",
"M" => "Modified",
"O" => "Overruled",
"CO" => "Concurring Opinion",
"SO" => "Seperated Opinion"
}
"A" => "Affirmed",
"C" => "Cited",
"D" => "Distinguished",
"F" => "Footnote",
"I" => "Illustrative",
"M" => "Modified",
"O" => "Overruled",
"CO" => "Concurring Opinion",
"SO" => "Seperated Opinion"
}.freeze
annomarks.each { |k, v| Annomark.create(name: v, code: k) } if Annomark.count.zero?
Doctrine.destroy_all
doctrine = Doctrine.new
doctrine.document = Cdao::Jurisprudence.first
doctrine.content = "Dasdsadsadsa"
doctrine.save
doctrine.subject_ids = Cdao::Subject.first(3).map(&:id)
doctrine = Doctrine.first
annotation = doctrine.annotations.new
annotation.document = Cdao::Jurisprudence.second
annotation.annomark = Annomark.first
annotation.save
end
Annotation.destroy_all
Cdao::Subject.find_each.with_index do |subject, index|
doctrine = Doctrine.new
doctrine.document = Cdao::Jurisprudence.first(index + 1).last
doctrine.content = Faker::Lorem.paragraph
doctrine.save
doctrine.subject_ids = [subject.id]
annotation = doctrine.annotations.new
annotation.document = Cdao::Jurisprudence.last(index + 1).first
annotation.annomark_ids = [Faker::Number.between(from: Annomark.first.id, to: Annomark.last.id)]
annotation.save
annotation_document = annotation.annotation_documents.new
annotation_document.document = Cdao::Jurisprudence.last(index + 101).first
annotation_document.save
end

Loading…
Cancel
Save