Class: CreateLocalAuthorities

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/sufia/models/templates/migrations/create_local_authorities.rb

Class Method Summary collapse

Class Method Details

.downObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/sufia/models/templates/migrations/create_local_authorities.rb', line 37

def self.down
  drop_table :local_authority_entries
  drop_table :local_authorities
  drop_table :domain_terms
  drop_table :domain_terms_local_authorities
  drop_table :subject_local_authority_entries
  remove_index :local_authority_entries, name: "entries_by_term_and_label"
  remove_index :local_authority_entries, name: "entries_by_term_and_uri"
  remove_index :domain_terms, name: "terms_by_model_and_term"
  remove_index :subject_local_authority_entries, name: 'entries_by_lower_label'
  remove_index :domain_terms_local_authorities, name: 'dtla_by_ids1'
  remove_index :domain_terms_local_authorities, name: 'dtla_by_ids2'
end

.upObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/sufia/models/templates/migrations/create_local_authorities.rb', line 2

def self.up
  create_table :local_authority_entries, force: true do |t|
    t.integer :local_authority_id
    t.string :label
    t.string :uri
  end

  create_table :local_authorities, force: true do |t|
    t.string :name, unique: true
  end

  create_table :domain_terms, force: true do |t|
    t.string :model
    t.string :term
  end

  create_table :domain_terms_local_authorities, id: false do |t|
    t.integer :domain_term_id, foreign_key: true
    t.integer :local_authority_id, foreign_key: true
  end

  create_table :subject_local_authority_entries, force: true do |t|
    t.string :label
    t.string :lowerLabel
    t.string :url
  end

  add_index :local_authority_entries, [:local_authority_id, :label], name: 'entries_by_term_and_label'
  add_index :local_authority_entries, [:local_authority_id, :uri], name: 'entries_by_term_and_uri'
  add_index :domain_terms, [:model, :term], name: 'terms_by_model_and_term'
  add_index :domain_terms_local_authorities, [:local_authority_id, :domain_term_id], name: 'dtla_by_ids1'
  add_index :domain_terms_local_authorities, [:domain_term_id, :local_authority_id], name: 'dtla_by_ids2'
  add_index :subject_local_authority_entries, [:lowerLabel], name: 'entries_by_lower_label'
end