Browse Source

Implement initial db seed

pull/9/head
Angel Aviel Domaoan 4 years ago committed by Angel Aviel Domaoan
parent
commit
6fbd422686
  1. 2
      Gemfile
  2. 16
      Gemfile.lock
  3. 2
      db/migrate/20220120043115_create_annomarks.rb
  4. 32
      db/seeds.rb

2
Gemfile

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

16
Gemfile.lock

@ -156,8 +156,19 @@ GEM
warden (~> 1.2.3)
ed25519 (1.3.0)
erubi (1.10.0)
faraday (2.0.1)
faraday-net_http (~> 2.0)
faker (2.19.0)
i18n (>= 1.6, < 2)
faraday (1.9.3)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-net_http (2.0.1)
ffi (1.15.4)
@ -432,6 +443,7 @@ DEPENDENCIES
capybara (>= 3.26)
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

32
db/seeds.rb

@ -8,6 +8,19 @@
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",
@ -18,23 +31,26 @@ annomarks = {
"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
Annotation.destroy_all
Cdao::Subject.find_each.with_index do |subject, index|
doctrine = Doctrine.new
doctrine.document = Cdao::Jurisprudence.first
doctrine.content = "Dasdsadsadsa"
doctrine.document = Cdao::Jurisprudence.first(index + 1).last
doctrine.content = Faker::Lorem.paragraph
doctrine.save
doctrine.subject_ids = Cdao::Subject.first(3).map(&:id)
doctrine.subject_ids = [subject.id]
doctrine = Doctrine.first
annotation = doctrine.annotations.new
annotation.document = Cdao::Jurisprudence.second
annotation.annomark = Annomark.first
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