From 6fbd422686d1a8a2a7fa91cbb8be6403ccb61ece Mon Sep 17 00:00:00 2001 From: Angel Aviel Domaoan Date: Mon, 31 Jan 2022 05:37:23 +0000 Subject: [PATCH] Implement initial db seed --- Gemfile | 2 + Gemfile.lock | 16 ++++- db/migrate/20220120043115_create_annomarks.rb | 2 +- db/seeds.rb | 66 ++++++++++++------- 4 files changed, 58 insertions(+), 28 deletions(-) diff --git a/Gemfile b/Gemfile index 9cc84a1..f6dc169 100644 --- a/Gemfile +++ b/Gemfile @@ -120,3 +120,5 @@ group :development do gem "bcrypt_pbkdf", "~> 1.1" gem "ed25519", "~> 1.3" end + +gem "faker", "~> 2.19" diff --git a/Gemfile.lock b/Gemfile.lock index 0d451f3..8ff8f82 100644 --- a/Gemfile.lock +++ b/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) diff --git a/db/migrate/20220120043115_create_annomarks.rb b/db/migrate/20220120043115_create_annomarks.rb index 72a1b42..5badbc5 100644 --- a/db/migrate/20220120043115_create_annomarks.rb +++ b/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 diff --git a/db/seeds.rb b/db/seeds.rb index 674ab62..534fdb4 100644 --- a/db/seeds.rb +++ b/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 \ No newline at end of file +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