Class: RTM::AR::TMDM::InitialSchema

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/rtm/activerecord/001_initial_schema.rb

Class Method Summary collapse

Class Method Details

.downObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/rtm/activerecord/001_initial_schema.rb', line 95

def self.down
  drop_table :topic_maps
  drop_table :topic
  drop_table :associations
  drop_table :roles
  drop_table :names
  drop_table :occurrences
  drop_table :variants
  drop_table :scoped_objects_topics
end

.upObject



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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rtm/activerecord/001_initial_schema.rb', line 10

def self.up
  create_table :topic_maps do |t|
    t.column :base_locator, :string, :null => false
  end
  create_table :topics do |t|
    t.column :topic_map_id, :integer, :null => false
    t.column :reified_id, :integer
    t.column :reified_type, :string
  end
  create_table :associations do |t|
    t.column :topic_map_id, :integer, :null => false
    t.column :ttype_id, :integer
  end
  create_table :roles do |t|
    t.column :association_id, :integer, :null => false
    t.column :ttype_id, :integer
    t.column :topic_id, :integer
  end
  create_table :names do |t|
    t.column :topic_id, :integer, :null => false
    t.column :ttype_id, :integer
    t.column :value, :string
  end
  create_table :occurrences do |t|
    t.column :topic_id, :integer, :null => false
    t.column :ttype_id, :integer
    t.column :value, :text
    t.column :datatype, :string
  end
  create_table :variants do |t|
    t.column :name_id, :integer, :null => false
    t.column :value, :text
    t.column :datatype, :string
  end
  create_table :item_identifiers do |t|
    t.column :topic_map_id, :integer, :null => false
    t.column :reference, :string, :null => false
    t.column :construct_id, :integer
    t.column :construct_type, :string
  end
  create_table :subject_identifiers do |t|
    t.column :topic_map_id, :integer, :null => false
    t.column :reference, :string, :null => false
    t.column :topic_id, :integer
  end
  create_table :subject_locators do |t|
    t.column :topic_map_id, :integer, :null => false
    t.column :reference, :string, :null => false
    t.column :topic_id, :integer
  end
  create_table :scoped_objects_topics do |t|
    t.column :scoped_object_id, :integer
    t.column :scoped_object_type, :string
    t.column :topic_id, :integer
  end
#          execute("
#            create view associations_rolecount as
#              select a.id as id, a.topic_map_id as topic_map_id, a.ttype_id as ttype_id, count(a.id) as rcnt
#                from associations a inner join association_roles r1 on a.id == r1.association_id;
#          ")
#
#          execute("
#            create view associations_cache as
#              select distinct
#                 a.id as id,  a.topic_map_id, a.ttype_id, a.rcnt,
#                 r1.id as role1_id, r1.ttype_id as type1_id, r1.topic_id as player1_id,
#                 r2.id as role2_id, r2.ttype_id as type2_id, r2.topic_id as player2_id
#              from associations_rolecount a
#                inner join association_roles r1 on a.id == r1.association_id
#                inner join association_roles r2 on a.id == r2.association_id
#              where r1.id != r2.id;
#          ")
#          execute("
#            create view associationcache as
#              select distinct
#                 a.id as association_id,  a.topic_map_id, a.ttype_id,
#                 r1.id as association_role1_id, r1.ttype_id as role_type1_id, r1.topic_id as player1_id,
#                 r2.id as association_role2_id, r2.ttype_id as role_type2_id, r2.topic_id as player2_id
#              from associations a
#                inner join association_roles r1 on a.id == r1.association_id
#                inner join association_roles r2 on a.id == r2.association_id
#              where r1.id != r2.id
#            ")
end