-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathactive_record.rb
More file actions
124 lines (96 loc) · 3.85 KB
/
active_record.rb
File metadata and controls
124 lines (96 loc) · 3.85 KB
1
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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
require "logger"
require "active_record"
ENV["DB"] = "mysql" unless ENV["DB"]
database_configuration = ENV["CI"] ? "test/support/ci_database.yml" : "test/support/database.yml"
ActiveRecord::Base.configurations = YAML.safe_load(IO.read(database_configuration))
ActiveRecord::Base.establish_connection(ENV["DB"].to_sym)
ActiveRecord::Migration.suppress_messages do
ActiveRecord::Schema.define version: 0 do
create_table :lists, force: true do |t|
t.string :name
end
create_table :entities, force: true do |t|
t.string :name
t.integer :position, null: false
t.references :includable, polymorphic: true
end
add_index :entities, [:includable_id, :includable_type, :position], unique: true, name: "index_entities_on_includable_and_position"
create_table :items, force: true do |t|
t.string :name
t.integer :position, null: false
t.references :list, null: false
end
add_index :items, [:list_id, :position], unique: true
create_table :new_items, force: true do |t|
t.string :name
t.integer :position
t.integer :other_position
t.references :list, null: false
end
create_table :default_scope_items, force: true do |t|
t.string :name
t.integer :position, null: false
t.references :list, null: false
end
add_index :default_scope_items, [:list_id, :position], unique: true
create_table :composite_primary_key_items, primary_key: [:item_id, :account_id], force: true do |t|
t.integer :item_id, null: false
t.integer :account_id, null: false
t.string :name
t.integer :position, null: false
t.references :list, null: false
end
add_index :composite_primary_key_items, [:list_id, :position], unique: true
create_table :composite_foreign_key_items, force: true do |t|
t.string :name
t.integer :position, null: false
t.integer :cpki_item_id, null: false
t.integer :cpki_account_id, null: false
end
add_index :composite_foreign_key_items, [:cpki_item_id, :cpki_account_id, :position], unique: true, name: "index_cfki_on_scope_and_position"
create_table :categories, force: true do |t|
t.string :name
t.integer :position, null: false
t.references :parent
end
add_index :categories, [:parent_id, :position], unique: true
create_table :products, force: true do |t|
t.string :name
t.integer :position, null: false
end
add_index :products, :position, unique: true
create_table :categorised_items, force: true do |t|
t.string :name
t.integer :position, null: false
t.integer :category_position, null: false
t.references :list, null: false
t.references :category, null: false
end
add_index :categorised_items, [:list_id, :position], unique: true, name: "index_on_list_id_and_position"
add_index :categorised_items, [:list_id, :category_id, :category_position], unique: true, name: "index_on_list_id_category_id_and_category_position"
create_table :authors, force: true do |t|
t.string :name
t.string :type
t.boolean :enabled, default: true
t.integer :position, null: false
t.references :list, null: false
end
add_index :authors, [:list_id, :enabled, :position], unique: true
create_table :blogs, force: true do |t|
t.string :name
t.boolean :enabled, default: true
t.integer :position, null: false
end
add_index :blogs, [:position, :enabled], unique: true
create_table :posts, force: true do |t|
t.string :name
t.integer :order, null: false
t.integer :position, null: false
t.references :blog
end
add_index :posts, [:blog_id, :position], unique: true
add_index :posts, :order, unique: true
end
end
# Uncomment the following line to enable SQL logging
# ActiveRecord::Base.logger = ActiveSupport::Logger.new($stdout)