activerecord.rb
2.02 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
require "active_record"
# for debugging
ActiveRecord::Base.logger = $logger
# rails does this in activerecord/lib/active_record/railtie.rb
if ActiveRecord::VERSION::MAJOR >= 7
ActiveRecord.default_timezone = :utc
else
ActiveRecord::Base.default_timezone = :utc
end
ActiveRecord::Base.time_zone_aware_attributes = true
# migrations
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
require_relative "apartment" if defined?(Apartment)
ActiveRecord::Migration.verbose = ENV["VERBOSE"]
ActiveRecord::Schema.define do
create_table :products do |t|
t.string :name
t.integer :store_id
t.boolean :in_stock
t.boolean :backordered
t.integer :orders_count
t.decimal :found_rate
t.integer :price
t.string :color
t.decimal :latitude, precision: 10, scale: 7
t.decimal :longitude, precision: 10, scale: 7
t.text :description
t.text :alt_description
t.timestamps null: true
end
create_table :stores do |t|
t.string :name
end
create_table :regions do |t|
t.string :name
t.text :text
end
create_table :speakers do |t|
t.string :name
end
create_table :animals do |t|
t.string :name
t.string :type
end
create_table :skus, id: :uuid do |t|
t.string :name
end
create_table :songs do |t|
t.string :name
end
create_table :bands do |t|
t.string :name
t.boolean :active
end
create_table :artists do |t|
t.string :name
t.boolean :active
t.boolean :should_index
end
end
class Product < ActiveRecord::Base
belongs_to :store
end
class Store < ActiveRecord::Base
has_many :products
end
class Region < ActiveRecord::Base
end
class Speaker < ActiveRecord::Base
end
class Animal < ActiveRecord::Base
end
class Dog < Animal
end
class Cat < Animal
end
class Sku < ActiveRecord::Base
end
class Song < ActiveRecord::Base
end
class Band < ActiveRecord::Base
default_scope { where(active: true).order(:name) }
end
class Artist < ActiveRecord::Base
default_scope { where(active: true).order(:name) }
end