activerecord 1.14.4 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (159) hide show
  1. data/CHANGELOG +400 -1
  2. data/README +2 -2
  3. data/RUNNING_UNIT_TESTS +21 -3
  4. data/Rakefile +55 -10
  5. data/lib/active_record.rb +10 -4
  6. data/lib/active_record/acts/list.rb +15 -4
  7. data/lib/active_record/acts/nested_set.rb +11 -12
  8. data/lib/active_record/acts/tree.rb +13 -14
  9. data/lib/active_record/aggregations.rb +46 -22
  10. data/lib/active_record/associations.rb +213 -162
  11. data/lib/active_record/associations/association_collection.rb +45 -15
  12. data/lib/active_record/associations/association_proxy.rb +32 -13
  13. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +18 -18
  14. data/lib/active_record/associations/has_many_association.rb +37 -17
  15. data/lib/active_record/associations/has_many_through_association.rb +120 -30
  16. data/lib/active_record/associations/has_one_association.rb +1 -1
  17. data/lib/active_record/attribute_methods.rb +75 -0
  18. data/lib/active_record/base.rb +282 -203
  19. data/lib/active_record/calculations.rb +95 -54
  20. data/lib/active_record/callbacks.rb +13 -24
  21. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +12 -1
  22. data/lib/active_record/connection_adapters/abstract/connection_specification.rb.rej +21 -0
  23. data/lib/active_record/connection_adapters/abstract/database_statements.rb +30 -4
  24. data/lib/active_record/connection_adapters/abstract/quoting.rb +16 -9
  25. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +121 -37
  26. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +55 -23
  27. data/lib/active_record/connection_adapters/abstract_adapter.rb +8 -0
  28. data/lib/active_record/connection_adapters/db2_adapter.rb +1 -11
  29. data/lib/active_record/connection_adapters/firebird_adapter.rb +364 -50
  30. data/lib/active_record/connection_adapters/frontbase_adapter.rb +861 -0
  31. data/lib/active_record/connection_adapters/mysql_adapter.rb +86 -33
  32. data/lib/active_record/connection_adapters/openbase_adapter.rb +4 -3
  33. data/lib/active_record/connection_adapters/oracle_adapter.rb +151 -127
  34. data/lib/active_record/connection_adapters/postgresql_adapter.rb +125 -48
  35. data/lib/active_record/connection_adapters/sqlite_adapter.rb +38 -10
  36. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +183 -155
  37. data/lib/active_record/connection_adapters/sybase_adapter.rb +190 -212
  38. data/lib/active_record/deprecated_associations.rb +24 -10
  39. data/lib/active_record/deprecated_finders.rb +4 -1
  40. data/lib/active_record/fixtures.rb +37 -23
  41. data/lib/active_record/locking/optimistic.rb +106 -0
  42. data/lib/active_record/locking/pessimistic.rb +77 -0
  43. data/lib/active_record/migration.rb +8 -5
  44. data/lib/active_record/observer.rb +73 -34
  45. data/lib/active_record/reflection.rb +21 -7
  46. data/lib/active_record/schema_dumper.rb +33 -5
  47. data/lib/active_record/timestamp.rb +23 -34
  48. data/lib/active_record/transactions.rb +37 -30
  49. data/lib/active_record/validations.rb +46 -30
  50. data/lib/active_record/vendor/mysql.rb +20 -5
  51. data/lib/active_record/version.rb +2 -2
  52. data/lib/active_record/wrappings.rb +1 -2
  53. data/lib/active_record/xml_serialization.rb +308 -0
  54. data/test/aaa_create_tables_test.rb +5 -1
  55. data/test/abstract_unit.rb +18 -8
  56. data/test/{active_schema_mysql.rb → active_schema_test_mysql.rb} +2 -2
  57. data/test/adapter_test.rb +9 -7
  58. data/test/adapter_test_sqlserver.rb +81 -0
  59. data/test/aggregations_test.rb +29 -0
  60. data/test/{association_callbacks_test.rb → associations/callbacks_test.rb} +10 -8
  61. data/test/{associations_cascaded_eager_loading_test.rb → associations/cascaded_eager_loading_test.rb} +35 -3
  62. data/test/{associations_go_eager_test.rb → associations/eager_test.rb} +36 -2
  63. data/test/{associations_extensions_test.rb → associations/extension_test.rb} +5 -0
  64. data/test/{associations_join_model_test.rb → associations/join_model_test.rb} +118 -8
  65. data/test/associations_test.rb +339 -45
  66. data/test/attribute_methods_test.rb +49 -0
  67. data/test/base_test.rb +321 -67
  68. data/test/calculations_test.rb +48 -10
  69. data/test/callbacks_test.rb +13 -0
  70. data/test/connection_test_firebird.rb +8 -0
  71. data/test/connections/native_db2/connection.rb +18 -17
  72. data/test/connections/native_firebird/connection.rb +19 -17
  73. data/test/connections/native_frontbase/connection.rb +27 -0
  74. data/test/connections/native_mysql/connection.rb +18 -15
  75. data/test/connections/native_openbase/connection.rb +14 -15
  76. data/test/connections/native_oracle/connection.rb +16 -12
  77. data/test/connections/native_postgresql/connection.rb +16 -17
  78. data/test/connections/native_sqlite/connection.rb +3 -6
  79. data/test/connections/native_sqlite3/connection.rb +3 -6
  80. data/test/connections/native_sqlserver/connection.rb +16 -17
  81. data/test/connections/native_sqlserver_odbc/connection.rb +18 -19
  82. data/test/connections/native_sybase/connection.rb +16 -17
  83. data/test/datatype_test_postgresql.rb +52 -0
  84. data/test/defaults_test.rb +52 -10
  85. data/test/deprecated_associations_test.rb +151 -107
  86. data/test/deprecated_finder_test.rb +83 -66
  87. data/test/empty_date_time_test.rb +25 -0
  88. data/test/finder_test.rb +118 -11
  89. data/test/fixtures/accounts.yml +6 -1
  90. data/test/fixtures/author.rb +27 -4
  91. data/test/fixtures/categorizations.yml +8 -2
  92. data/test/fixtures/category.rb +1 -2
  93. data/test/fixtures/comments.yml +0 -6
  94. data/test/fixtures/companies.yml +6 -1
  95. data/test/fixtures/company.rb +23 -1
  96. data/test/fixtures/company_in_module.rb +8 -10
  97. data/test/fixtures/customer.rb +2 -2
  98. data/test/fixtures/customers.yml +9 -0
  99. data/test/fixtures/db_definitions/db2.drop.sql +1 -0
  100. data/test/fixtures/db_definitions/db2.sql +9 -0
  101. data/test/fixtures/db_definitions/firebird.drop.sql +3 -0
  102. data/test/fixtures/db_definitions/firebird.sql +13 -1
  103. data/test/fixtures/db_definitions/frontbase.drop.sql +31 -0
  104. data/test/fixtures/db_definitions/frontbase.sql +262 -0
  105. data/test/fixtures/db_definitions/frontbase2.drop.sql +1 -0
  106. data/test/fixtures/db_definitions/frontbase2.sql +4 -0
  107. data/test/fixtures/db_definitions/mysql.drop.sql +1 -0
  108. data/test/fixtures/db_definitions/mysql.sql +23 -14
  109. data/test/fixtures/db_definitions/openbase.sql +13 -1
  110. data/test/fixtures/db_definitions/oracle.drop.sql +2 -0
  111. data/test/fixtures/db_definitions/oracle.sql +29 -2
  112. data/test/fixtures/db_definitions/postgresql.drop.sql +3 -1
  113. data/test/fixtures/db_definitions/postgresql.sql +13 -3
  114. data/test/fixtures/db_definitions/schema.rb +29 -1
  115. data/test/fixtures/db_definitions/sqlite.drop.sql +1 -0
  116. data/test/fixtures/db_definitions/sqlite.sql +12 -3
  117. data/test/fixtures/db_definitions/sqlserver.drop.sql +3 -0
  118. data/test/fixtures/db_definitions/sqlserver.sql +35 -0
  119. data/test/fixtures/db_definitions/sybase.drop.sql +2 -0
  120. data/test/fixtures/db_definitions/sybase.sql +13 -4
  121. data/test/fixtures/developer.rb +12 -0
  122. data/test/fixtures/edge.rb +5 -0
  123. data/test/fixtures/edges.yml +6 -0
  124. data/test/fixtures/funny_jokes.yml +3 -7
  125. data/test/fixtures/migrations_with_decimal/1_give_me_big_numbers.rb +15 -0
  126. data/test/fixtures/migrations_with_missing_versions/1000_people_have_middle_names.rb +9 -0
  127. data/test/fixtures/migrations_with_missing_versions/1_people_have_last_names.rb +9 -0
  128. data/test/fixtures/migrations_with_missing_versions/3_we_need_reminders.rb +12 -0
  129. data/test/fixtures/migrations_with_missing_versions/4_innocent_jointable.rb +12 -0
  130. data/test/fixtures/mixin.rb +15 -0
  131. data/test/fixtures/mixins.yml +38 -0
  132. data/test/fixtures/post.rb +3 -2
  133. data/test/fixtures/project.rb +3 -1
  134. data/test/fixtures/topic.rb +6 -1
  135. data/test/fixtures/topics.yml +4 -4
  136. data/test/fixtures/vertex.rb +9 -0
  137. data/test/fixtures/vertices.yml +4 -0
  138. data/test/fixtures_test.rb +45 -0
  139. data/test/inheritance_test.rb +67 -6
  140. data/test/lifecycle_test.rb +40 -19
  141. data/test/locking_test.rb +170 -26
  142. data/test/method_scoping_test.rb +2 -2
  143. data/test/migration_test.rb +387 -110
  144. data/test/migration_test_firebird.rb +124 -0
  145. data/test/mixin_nested_set_test.rb +14 -2
  146. data/test/mixin_test.rb +56 -18
  147. data/test/modules_test.rb +8 -2
  148. data/test/multiple_db_test.rb +2 -2
  149. data/test/pk_test.rb +1 -0
  150. data/test/reflection_test.rb +8 -2
  151. data/test/schema_authorization_test_postgresql.rb +75 -0
  152. data/test/schema_dumper_test.rb +40 -4
  153. data/test/table_name_test_sqlserver.rb +23 -0
  154. data/test/threaded_connections_test.rb +19 -16
  155. data/test/transactions_test.rb +86 -72
  156. data/test/validations_test.rb +126 -56
  157. data/test/xml_serialization_test.rb +125 -0
  158. metadata +45 -11
  159. data/lib/active_record/locking.rb +0 -79
@@ -3,12 +3,30 @@ class Author < ActiveRecord::Base
3
3
  has_many :posts_with_comments, :include => :comments, :class_name => "Post"
4
4
  has_many :posts_with_categories, :include => :categories, :class_name => "Post"
5
5
  has_many :posts_with_comments_and_categories, :include => [ :comments, :categories ], :order => "posts.id", :class_name => "Post"
6
+ has_many :posts_with_extension, :class_name => "Post" do #, :extend => ProxyTestExtension
7
+ def testing_proxy_owner
8
+ proxy_owner
9
+ end
10
+ def testing_proxy_reflection
11
+ proxy_reflection
12
+ end
13
+ def testing_proxy_target
14
+ proxy_target
15
+ end
16
+ end
6
17
  has_many :comments, :through => :posts
7
18
  has_many :funky_comments, :through => :posts, :source => :comments
8
19
 
9
- has_many :special_posts, :class_name => "Post"
10
- has_many :hello_posts, :class_name => "Post", :conditions=>"\#{aliased_table_name}.body = 'hello'"
11
- has_many :nonexistent_posts, :class_name => "Post", :conditions=>"\#{aliased_table_name}.body = 'nonexistent'"
20
+ has_many :special_posts
21
+ has_many :special_post_comments, :through => :special_posts, :source => :comments
22
+
23
+ has_many :special_nonexistant_posts, :class_name => "SpecialPost", :conditions => "posts.body = 'nonexistant'"
24
+ has_many :special_nonexistant_post_comments, :through => :special_nonexistant_posts, :source => :comments, :conditions => "comments.post_id = 0"
25
+
26
+ has_many :hello_posts, :class_name => "Post", :conditions => "posts.body = 'hello'"
27
+ has_many :hello_post_comments, :through => :hello_posts, :source => :comments
28
+
29
+ has_many :other_posts, :class_name => "Post"
12
30
  has_many :posts_with_callbacks, :class_name => "Post", :before_add => :log_before_adding,
13
31
  :after_add => :log_after_adding,
14
32
  :before_remove => :log_before_removing,
@@ -26,6 +44,11 @@ class Author < ActiveRecord::Base
26
44
  has_many :categorizations
27
45
  has_many :categories, :through => :categorizations
28
46
 
47
+ has_many :categories_like_general, :through => :categorizations, :source => :category, :class_name => 'Category', :conditions => { :name => 'General' }
48
+
49
+ has_many :categorized_posts, :through => :categorizations, :source => :post
50
+ has_many :unique_categorized_posts, :through => :categorizations, :source => :post, :uniq => true
51
+
29
52
  has_many :nothings, :through => :kateggorisatons, :class_name => 'Category'
30
53
 
31
54
  has_many :author_favorites
@@ -73,4 +96,4 @@ end
73
96
  class AuthorFavorite < ActiveRecord::Base
74
97
  belongs_to :author
75
98
  belongs_to :favorite_author, :class_name => "Author", :foreign_key => 'favorite_author_id'
76
- end
99
+ end
@@ -3,9 +3,15 @@ david_welcome_general:
3
3
  author_id: 1
4
4
  post_id: 1
5
5
  category_id: 1
6
-
6
+
7
7
  mary_thinking_sti:
8
8
  id: 2
9
9
  author_id: 2
10
10
  post_id: 2
11
- category_id: 3
11
+ category_id: 3
12
+
13
+ mary_thinking_general:
14
+ id: 3
15
+ author_id: 2
16
+ post_id: 2
17
+ category_id: 1
@@ -1,8 +1,7 @@
1
1
  class Category < ActiveRecord::Base
2
2
  has_and_belongs_to_many :posts
3
3
  has_and_belongs_to_many :special_posts, :class_name => "Post"
4
- has_and_belongs_to_many :hello_posts, :class_name => "Post", :conditions => "\#{aliased_table_name}.body = 'hello'"
5
- has_and_belongs_to_many :nonexistent_posts, :class_name => "Post", :conditions=>"\#{aliased_table_name}.body = 'nonexistent'"
4
+ has_and_belongs_to_many :other_posts, :class_name => "Post"
6
5
 
7
6
  def self.what_are_you
8
7
  'a category...'
@@ -16,12 +16,6 @@ does_it_hurt:
16
16
  body: Don't think too hard
17
17
  type: SpecialComment
18
18
 
19
- eager_sti_on_associations_comment:
20
- id: 4
21
- post_id: 4
22
- body: Normal type
23
- type: Comment
24
-
25
19
  eager_sti_on_associations_vs_comment:
26
20
  id: 5
27
21
  post_id: 4
@@ -47,4 +47,9 @@ leetsoft:
47
47
  jadedpixel:
48
48
  id: 8
49
49
  name: Jadedpixel
50
- client_of: 6
50
+ client_of: 6
51
+
52
+ odegy:
53
+ id: 9
54
+ name: Odegy
55
+ type: ExclusivelyDependentFirm
@@ -5,6 +5,10 @@ class Company < ActiveRecord::Base
5
5
  validates_presence_of :name
6
6
 
7
7
  has_one :dummy_account, :foreign_key => "firm_id", :class_name => "Account"
8
+
9
+ def arbitrary_method
10
+ "I am Jack's profound disappointment"
11
+ end
8
12
  end
9
13
 
10
14
 
@@ -18,6 +22,8 @@ class Firm < Company
18
22
  has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all
19
23
  has_many :limited_clients, :class_name => "Client", :order => "id", :limit => 1
20
24
  has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
25
+ has_many :clients_with_interpolated_conditions, :class_name => "Client", :conditions => 'rating > #{rating}'
26
+ has_many :clients_like_ms_with_hash_conditions, :conditions => { :name => 'Microsoft' }, :class_name => "Client", :order => "id"
21
27
  has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
22
28
  has_many :clients_using_counter_sql, :class_name => "Client",
23
29
  :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}',
@@ -28,6 +34,7 @@ class Firm < Company
28
34
  has_many :no_clients_using_counter_sql, :class_name => "Client",
29
35
  :finder_sql => 'SELECT * FROM companies WHERE client_of = 1000',
30
36
  :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = 1000'
37
+ has_many :plain_clients, :class_name => 'Client'
31
38
 
32
39
  has_one :account, :foreign_key => "firm_id", :dependent => :destroy
33
40
  end
@@ -37,6 +44,9 @@ class DependentFirm < Company
37
44
  has_many :companies, :foreign_key => 'client_of', :order => "id", :dependent => :nullify
38
45
  end
39
46
 
47
+ class ExclusivelyDependentFirm < Company
48
+ has_one :account, :foreign_key => "firm_id", :dependent => :delete
49
+ end
40
50
 
41
51
  class Client < Company
42
52
  belongs_to :firm, :foreign_key => "client_of"
@@ -78,8 +88,20 @@ end
78
88
  class Account < ActiveRecord::Base
79
89
  belongs_to :firm
80
90
 
91
+ def self.destroyed_account_ids
92
+ @destroyed_account_ids ||= Hash.new { |h,k| h[k] = [] }
93
+ end
94
+
95
+ before_destroy do |account|
96
+ if account.firm
97
+ Account.destroyed_account_ids[account.firm.id] << account.id
98
+ end
99
+ true
100
+ end
101
+
102
+
81
103
  protected
82
104
  def validate
83
105
  errors.add_on_empty "credit_limit"
84
106
  end
85
- end
107
+ end
@@ -21,11 +21,7 @@ module MyApplication
21
21
 
22
22
  class Developer < ActiveRecord::Base
23
23
  has_and_belongs_to_many :projects
24
-
25
- protected
26
- def validate
27
- errors.add_on_boundary_breaking("name", 3..20)
28
- end
24
+ validates_length_of :name, :within => (3..20)
29
25
  end
30
26
 
31
27
  class Project < ActiveRecord::Base
@@ -46,11 +42,13 @@ module MyApplication
46
42
  end
47
43
 
48
44
  class Account < ActiveRecord::Base
49
- belongs_to :firm, :class_name => 'MyApplication::Business::Firm'
50
- belongs_to :qualified_billing_firm, :class_name => 'MyApplication::Billing::Firm'
51
- belongs_to :unqualified_billing_firm, :class_name => 'Firm'
52
- belongs_to :nested_qualified_billing_firm, :class_name => 'MyApplication::Billing::Nested::Firm'
53
- belongs_to :nested_unqualified_billing_firm, :class_name => 'Nested::Firm'
45
+ with_options(:foreign_key => :firm_id) do |i|
46
+ i.belongs_to :firm, :class_name => 'MyApplication::Business::Firm'
47
+ i.belongs_to :qualified_billing_firm, :class_name => 'MyApplication::Billing::Firm'
48
+ i.belongs_to :unqualified_billing_firm, :class_name => 'Firm'
49
+ i.belongs_to :nested_qualified_billing_firm, :class_name => 'MyApplication::Billing::Nested::Firm'
50
+ i.belongs_to :nested_unqualified_billing_firm, :class_name => 'Nested::Firm'
51
+ end
54
52
 
55
53
  protected
56
54
  def validate
@@ -1,7 +1,7 @@
1
1
  class Customer < ActiveRecord::Base
2
- composed_of :address, :mapping => [ %w(address_street street), %w(address_city city), %w(address_country country) ]
2
+ composed_of :address, :mapping => [ %w(address_street street), %w(address_city city), %w(address_country country) ], :allow_nil => true
3
3
  composed_of :balance, :class_name => "Money", :mapping => %w(balance amount)
4
- composed_of :gps_location
4
+ composed_of :gps_location, :allow_nil => true
5
5
  end
6
6
 
7
7
  class Address
@@ -6,3 +6,12 @@ david:
6
6
  address_city: Scary Town
7
7
  address_country: Loony Land
8
8
  gps_location: 35.544623640962634x-105.9309951055148
9
+
10
+ zaphod:
11
+ id: 2
12
+ name: Zaphod
13
+ balance: 62
14
+ address_street: Avenue Road
15
+ address_city: Hamlet Town
16
+ address_country: Nation Land
17
+ gps_location: NULL
@@ -28,3 +28,4 @@ DROP TABLE fk_test_has_pk;
28
28
  DROP TABLE fk_test_has_fk;
29
29
  DROP TABLE keyboards;
30
30
  DROP TABLE legacy_things;
31
+ DROP TABLE numeric_data;
@@ -215,3 +215,12 @@ CREATE TABLE legacy_things (
215
215
  version INT DEFAULT 0,
216
216
  PRIMARY KEY (id)
217
217
  );
218
+
219
+ CREATE TABLE numeric_data (
220
+ id INT NOT NULL PRIMARY KEY,
221
+ bank_balance DECIMAL(10,2),
222
+ big_bank_balance DECIMAL(15,2),
223
+ world_population DECIMAL(10),
224
+ my_house_population DECIMAL(2),
225
+ decimal_number_with_default DECIMAL(3,2) DEFAULT 2.78
226
+ );
@@ -29,6 +29,7 @@ DROP TABLE fk_test_has_pk;
29
29
  DROP TABLE keyboards;
30
30
  DROP TABLE defaults;
31
31
  DROP TABLE legacy_things;
32
+ DROP TABLE numeric_data;
32
33
 
33
34
  DROP DOMAIN D_BOOLEAN;
34
35
 
@@ -56,3 +57,5 @@ DROP GENERATOR tasks_seq;
56
57
  DROP GENERATOR categories_seq;
57
58
  DROP GENERATOR keyboards_seq;
58
59
  DROP GENERATOR defaults_seq;
60
+ DROP GENERATOR legacy_things_seq;
61
+ DROP GENERATOR numeric_data_seq;
@@ -1,4 +1,4 @@
1
- CREATE DOMAIN D_BOOLEAN AS SMALLINT CHECK (VALUE IN (0, 1));
1
+ CREATE DOMAIN D_BOOLEAN AS SMALLINT CHECK (VALUE IN (0, 1) OR VALUE IS NULL);
2
2
 
3
3
  CREATE TABLE accounts (
4
4
  id BIGINT NOT NULL,
@@ -283,3 +283,15 @@ CREATE TABLE legacy_things (
283
283
  );
284
284
  CREATE GENERATOR legacy_things_seq;
285
285
  SET GENERATOR legacy_things_seq TO 10000;
286
+
287
+ CREATE TABLE numeric_data (
288
+ id BIGINT NOT NULL,
289
+ bank_balance DECIMAL(10,2),
290
+ big_bank_balance DECIMAL(15,2),
291
+ world_population DECIMAL(10),
292
+ my_house_population DECIMAL(2),
293
+ decimal_number_with_default DECIMAL(3,2) DEFAULT 2.78,
294
+ PRIMARY KEY (id)
295
+ );
296
+ CREATE GENERATOR numeric_data_seq;
297
+ SET GENERATOR numeric_data_seq TO 10000;
@@ -0,0 +1,31 @@
1
+ DROP TABLE accounts CASCADE;
2
+ DROP TABLE funny_jokes CASCADE;
3
+ DROP TABLE companies CASCADE;
4
+ DROP TABLE topics CASCADE;
5
+ DROP TABLE developers CASCADE;
6
+ DROP TABLE projects CASCADE;
7
+ DROP TABLE developers_projects CASCADE;
8
+ DROP TABLE orders CASCADE;
9
+ DROP TABLE customers CASCADE;
10
+ DROP TABLE movies CASCADE;
11
+ DROP TABLE subscribers CASCADE;
12
+ DROP TABLE booleantests CASCADE;
13
+ DROP TABLE auto_id_tests CASCADE;
14
+ DROP TABLE entrants CASCADE;
15
+ DROP TABLE colnametests CASCADE;
16
+ DROP TABLE mixins CASCADE;
17
+ DROP TABLE people CASCADE;
18
+ DROP TABLE readers CASCADE;
19
+ DROP TABLE binaries CASCADE;
20
+ DROP TABLE computers CASCADE;
21
+ DROP TABLE posts CASCADE;
22
+ DROP TABLE comments CASCADE;
23
+ DROP TABLE authors CASCADE;
24
+ DROP TABLE tasks CASCADE;
25
+ DROP TABLE categories CASCADE;
26
+ DROP TABLE categories_posts CASCADE;
27
+ DROP TABLE fk_test_has_fk CASCADE;
28
+ DROP TABLE fk_test_has_pk CASCADE;
29
+ DROP TABLE keyboards CASCADE;
30
+ DROP TABLE legacy_things CASCADE;
31
+ DROP TABLE numeric_data CASCADE;
@@ -0,0 +1,262 @@
1
+ CREATE TABLE accounts (
2
+ id integer DEFAULT unique,
3
+ firm_id integer,
4
+ credit_limit integer,
5
+ PRIMARY KEY (id)
6
+ );
7
+ SET UNIQUE FOR accounts(id);
8
+
9
+ CREATE TABLE funny_jokes (
10
+ id integer DEFAULT unique,
11
+ firm_id integer default NULL,
12
+ name character varying(50),
13
+ PRIMARY KEY (id)
14
+ );
15
+ SET UNIQUE FOR funny_jokes(id);
16
+
17
+ CREATE TABLE companies (
18
+ id integer DEFAULT unique,
19
+ "type" character varying(50),
20
+ "ruby_type" character varying(50),
21
+ firm_id integer,
22
+ name character varying(50),
23
+ client_of integer,
24
+ rating integer default 1,
25
+ PRIMARY KEY (id)
26
+ );
27
+ SET UNIQUE FOR companies(id);
28
+
29
+ CREATE TABLE topics (
30
+ id integer DEFAULT unique,
31
+ title character varying(255),
32
+ author_name character varying(255),
33
+ author_email_address character varying(255),
34
+ written_on timestamp,
35
+ bonus_time time,
36
+ last_read date,
37
+ content varchar(65536),
38
+ approved boolean default true,
39
+ replies_count integer default 0,
40
+ parent_id integer,
41
+ "type" character varying(50),
42
+ PRIMARY KEY (id)
43
+ );
44
+ SET UNIQUE FOR topics(id);
45
+
46
+ CREATE TABLE developers (
47
+ id integer DEFAULT unique,
48
+ name character varying(100),
49
+ salary integer DEFAULT 70000,
50
+ created_at timestamp,
51
+ updated_at timestamp,
52
+ PRIMARY KEY (id)
53
+ );
54
+ SET UNIQUE FOR developers(id);
55
+
56
+ CREATE TABLE projects (
57
+ id integer DEFAULT unique,
58
+ name character varying(100),
59
+ type varchar(255),
60
+ PRIMARY KEY (id)
61
+ );
62
+ SET UNIQUE FOR projects(id);
63
+
64
+ CREATE TABLE developers_projects (
65
+ developer_id integer NOT NULL,
66
+ project_id integer NOT NULL,
67
+ joined_on date,
68
+ access_level integer default 1
69
+ );
70
+
71
+ CREATE TABLE orders (
72
+ id integer DEFAULT unique,
73
+ name character varying(100),
74
+ billing_customer_id integer,
75
+ shipping_customer_id integer,
76
+ PRIMARY KEY (id)
77
+ );
78
+ SET UNIQUE FOR orders(id);
79
+
80
+ CREATE TABLE customers (
81
+ id integer DEFAULT unique,
82
+ name character varying(100),
83
+ balance integer default 0,
84
+ address_street character varying(100),
85
+ address_city character varying(100),
86
+ address_country character varying(100),
87
+ gps_location character varying(100),
88
+ PRIMARY KEY (id)
89
+ );
90
+ SET UNIQUE FOR customers(id);
91
+
92
+ CREATE TABLE movies (
93
+ movieid integer DEFAULT unique,
94
+ name varchar(65536),
95
+ PRIMARY KEY (movieid)
96
+ );
97
+ SET UNIQUE FOR movies(movieid);
98
+
99
+ CREATE TABLE subscribers (
100
+ nick varchar(65536) NOT NULL,
101
+ name varchar(65536),
102
+ PRIMARY KEY (nick)
103
+ );
104
+
105
+ CREATE TABLE booleantests (
106
+ id integer DEFAULT unique,
107
+ value boolean,
108
+ PRIMARY KEY (id)
109
+ );
110
+ SET UNIQUE FOR booleantests(id);
111
+
112
+ CREATE TABLE auto_id_tests (
113
+ auto_id integer DEFAULT unique,
114
+ value integer,
115
+ PRIMARY KEY (auto_id)
116
+ );
117
+ SET UNIQUE FOR auto_id_tests(auto_id);
118
+
119
+ CREATE TABLE entrants (
120
+ id integer DEFAULT unique,
121
+ name varchar(65536),
122
+ course_id integer,
123
+ PRIMARY KEY (id)
124
+ );
125
+ SET UNIQUE FOR entrants(id);
126
+
127
+ CREATE TABLE colnametests (
128
+ id integer DEFAULT unique,
129
+ "references" integer NOT NULL,
130
+ PRIMARY KEY (id)
131
+ );
132
+ SET UNIQUE FOR colnametests(id);
133
+
134
+ CREATE TABLE mixins (
135
+ id integer DEFAULT unique,
136
+ parent_id integer,
137
+ type character varying(100),
138
+ pos integer,
139
+ lft integer,
140
+ rgt integer,
141
+ root_id integer,
142
+ created_at timestamp,
143
+ updated_at timestamp,
144
+ PRIMARY KEY (id)
145
+ );
146
+ SET UNIQUE FOR mixins(id);
147
+
148
+ CREATE TABLE people (
149
+ id integer DEFAULT unique,
150
+ first_name varchar(65536),
151
+ lock_version integer default 0,
152
+ PRIMARY KEY (id)
153
+ );
154
+ SET UNIQUE FOR people(id);
155
+
156
+ CREATE TABLE readers (
157
+ id integer DEFAULT unique,
158
+ post_id INTEGER NOT NULL,
159
+ person_id INTEGER NOT NULL,
160
+ PRIMARY KEY (id)
161
+ );
162
+ SET UNIQUE FOR readers(id);
163
+
164
+ CREATE TABLE binaries (
165
+ id integer DEFAULT unique,
166
+ data BLOB,
167
+ PRIMARY KEY (id)
168
+ );
169
+ SET UNIQUE FOR binaries(id);
170
+
171
+ CREATE TABLE computers (
172
+ id integer DEFAULT unique,
173
+ developer integer NOT NULL,
174
+ "extendedWarranty" integer NOT NULL,
175
+ PRIMARY KEY (id)
176
+ );
177
+ SET UNIQUE FOR computers(id);
178
+
179
+ CREATE TABLE posts (
180
+ id integer DEFAULT unique,
181
+ author_id integer,
182
+ title varchar(255),
183
+ type varchar(255),
184
+ body varchar(65536),
185
+ PRIMARY KEY (id)
186
+ );
187
+ SET UNIQUE FOR posts(id);
188
+
189
+ CREATE TABLE comments (
190
+ id integer DEFAULT unique,
191
+ post_id integer,
192
+ type varchar(255),
193
+ body varchar(65536),
194
+ PRIMARY KEY (id)
195
+ );
196
+ SET UNIQUE FOR comments(id);
197
+
198
+ CREATE TABLE authors (
199
+ id integer DEFAULT unique,
200
+ name varchar(255) default NULL,
201
+ PRIMARY KEY (id)
202
+ );
203
+ SET UNIQUE FOR authors(id);
204
+
205
+ CREATE TABLE tasks (
206
+ id integer DEFAULT unique,
207
+ starting timestamp,
208
+ ending timestamp,
209
+ PRIMARY KEY (id)
210
+ );
211
+ SET UNIQUE FOR tasks(id);
212
+
213
+ CREATE TABLE categories (
214
+ id integer DEFAULT unique,
215
+ name varchar(255),
216
+ type varchar(255),
217
+ PRIMARY KEY (id)
218
+ );
219
+ SET UNIQUE FOR categories(id);
220
+
221
+ CREATE TABLE categories_posts (
222
+ category_id integer NOT NULL,
223
+ post_id integer NOT NULL
224
+ );
225
+
226
+ CREATE TABLE fk_test_has_pk (
227
+ id INTEGER NOT NULL PRIMARY KEY
228
+ );
229
+ SET UNIQUE FOR fk_test_has_pk(id);
230
+
231
+ CREATE TABLE fk_test_has_fk (
232
+ id INTEGER NOT NULL PRIMARY KEY,
233
+ fk_id INTEGER NOT NULL REFERENCES fk_test_has_fk(id)
234
+ );
235
+ SET UNIQUE FOR fk_test_has_fk(id);
236
+
237
+ CREATE TABLE keyboards (
238
+ key_number integer DEFAULT unique,
239
+ "name" character varying(50),
240
+ PRIMARY KEY (key_number)
241
+ );
242
+ SET UNIQUE FOR keyboards(key_number);
243
+
244
+ create table "legacy_things"
245
+ (
246
+ "id" int,
247
+ "tps_report_number" int default NULL,
248
+ "version" int default 0 not null,
249
+ primary key ("id")
250
+ );
251
+ SET UNIQUE FOR legacy_things(id);
252
+
253
+ CREATE TABLE "numeric_data" (
254
+ "id" integer NOT NULL
255
+ "bank_balance" DECIMAL(10,2),
256
+ "big_bank_balance" DECIMAL(15,2),
257
+ "world_population" DECIMAL(10),
258
+ "my_house_population" DECIMAL(2),
259
+ "decimal_number_with_default" DECIMAL(3,2) DEFAULT 2.78,
260
+ primary key ("id")
261
+ );
262
+ SET UNIQUE FOR numeric_data(id);