activerecord 1.13.2 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. data/CHANGELOG +452 -10
  2. data/RUNNING_UNIT_TESTS +1 -1
  3. data/lib/active_record.rb +5 -2
  4. data/lib/active_record/acts/list.rb +1 -1
  5. data/lib/active_record/acts/tree.rb +29 -25
  6. data/lib/active_record/aggregations.rb +3 -2
  7. data/lib/active_record/associations.rb +783 -337
  8. data/lib/active_record/associations/association_collection.rb +7 -12
  9. data/lib/active_record/associations/association_proxy.rb +62 -24
  10. data/lib/active_record/associations/belongs_to_association.rb +27 -46
  11. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +50 -0
  12. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +38 -38
  13. data/lib/active_record/associations/has_many_association.rb +61 -56
  14. data/lib/active_record/associations/has_many_through_association.rb +144 -0
  15. data/lib/active_record/associations/has_one_association.rb +22 -16
  16. data/lib/active_record/base.rb +482 -182
  17. data/lib/active_record/calculations.rb +225 -0
  18. data/lib/active_record/callbacks.rb +7 -7
  19. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +162 -47
  20. data/lib/active_record/connection_adapters/abstract/quoting.rb +1 -1
  21. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +2 -1
  22. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +21 -1
  23. data/lib/active_record/connection_adapters/abstract_adapter.rb +34 -2
  24. data/lib/active_record/connection_adapters/db2_adapter.rb +107 -61
  25. data/lib/active_record/connection_adapters/mysql_adapter.rb +29 -6
  26. data/lib/active_record/connection_adapters/openbase_adapter.rb +349 -0
  27. data/lib/active_record/connection_adapters/{oci_adapter.rb → oracle_adapter.rb} +125 -59
  28. data/lib/active_record/connection_adapters/postgresql_adapter.rb +24 -21
  29. data/lib/active_record/connection_adapters/sqlite_adapter.rb +47 -8
  30. data/lib/active_record/connection_adapters/sqlserver_adapter.rb +36 -16
  31. data/lib/active_record/connection_adapters/sybase_adapter.rb +684 -0
  32. data/lib/active_record/fixtures.rb +42 -17
  33. data/lib/active_record/locking.rb +36 -15
  34. data/lib/active_record/migration.rb +111 -8
  35. data/lib/active_record/observer.rb +25 -1
  36. data/lib/active_record/reflection.rb +103 -41
  37. data/lib/active_record/schema.rb +2 -2
  38. data/lib/active_record/schema_dumper.rb +55 -18
  39. data/lib/active_record/timestamp.rb +6 -6
  40. data/lib/active_record/validations.rb +65 -40
  41. data/lib/active_record/vendor/db2.rb +10 -5
  42. data/lib/active_record/vendor/simple.rb +693 -702
  43. data/lib/active_record/version.rb +2 -2
  44. data/rakefile +4 -4
  45. data/test/aaa_create_tables_test.rb +25 -6
  46. data/test/abstract_unit.rb +39 -1
  47. data/test/adapter_test.rb +31 -4
  48. data/test/associations_cascaded_eager_loading_test.rb +106 -0
  49. data/test/associations_go_eager_test.rb +85 -16
  50. data/test/associations_join_model_test.rb +338 -0
  51. data/test/associations_test.rb +129 -50
  52. data/test/base_test.rb +204 -49
  53. data/test/binary_test.rb +1 -1
  54. data/test/calculations_test.rb +169 -0
  55. data/test/callbacks_test.rb +5 -23
  56. data/test/class_inheritable_attributes_test.rb +1 -1
  57. data/test/column_alias_test.rb +1 -1
  58. data/test/connections/native_mysql/connection.rb +1 -0
  59. data/test/connections/native_openbase/connection.rb +22 -0
  60. data/test/connections/{native_oci → native_oracle}/connection.rb +7 -9
  61. data/test/connections/native_sqlite/connection.rb +1 -1
  62. data/test/connections/native_sqlite3/connection.rb +1 -0
  63. data/test/connections/native_sqlite3/in_memory_connection.rb +1 -0
  64. data/test/connections/native_sybase/connection.rb +24 -0
  65. data/test/defaults_test.rb +18 -0
  66. data/test/deprecated_associations_test.rb +2 -2
  67. data/test/deprecated_finder_test.rb +0 -6
  68. data/test/finder_test.rb +26 -23
  69. data/test/fixtures/accounts.yml +10 -0
  70. data/test/fixtures/author.rb +31 -6
  71. data/test/fixtures/author_favorites.yml +4 -0
  72. data/test/fixtures/categories/special_categories.yml +9 -0
  73. data/test/fixtures/categories/subsubdir/arbitrary_filename.yml +4 -0
  74. data/test/fixtures/categories_posts.yml +4 -0
  75. data/test/fixtures/categorization.rb +5 -0
  76. data/test/fixtures/categorizations.yml +11 -0
  77. data/test/fixtures/category.rb +6 -0
  78. data/test/fixtures/company.rb +17 -5
  79. data/test/fixtures/company_in_module.rb +19 -5
  80. data/test/fixtures/db_definitions/db2.drop.sql +3 -0
  81. data/test/fixtures/db_definitions/db2.sql +121 -100
  82. data/test/fixtures/db_definitions/db22.sql +2 -2
  83. data/test/fixtures/db_definitions/firebird.drop.sql +4 -0
  84. data/test/fixtures/db_definitions/firebird.sql +26 -0
  85. data/test/fixtures/db_definitions/mysql.drop.sql +3 -0
  86. data/test/fixtures/db_definitions/mysql.sql +21 -1
  87. data/test/fixtures/db_definitions/openbase.drop.sql +2 -0
  88. data/test/fixtures/db_definitions/openbase.sql +282 -0
  89. data/test/fixtures/db_definitions/openbase2.drop.sql +2 -0
  90. data/test/fixtures/db_definitions/openbase2.sql +7 -0
  91. data/test/fixtures/db_definitions/{oci.drop.sql → oracle.drop.sql} +6 -0
  92. data/test/fixtures/db_definitions/{oci.sql → oracle.sql} +25 -4
  93. data/test/fixtures/db_definitions/{oci2.drop.sql → oracle2.drop.sql} +0 -0
  94. data/test/fixtures/db_definitions/{oci2.sql → oracle2.sql} +0 -0
  95. data/test/fixtures/db_definitions/postgresql.drop.sql +4 -0
  96. data/test/fixtures/db_definitions/postgresql.sql +22 -1
  97. data/test/fixtures/db_definitions/schema.rb +32 -0
  98. data/test/fixtures/db_definitions/sqlite.drop.sql +3 -0
  99. data/test/fixtures/db_definitions/sqlite.sql +18 -0
  100. data/test/fixtures/db_definitions/sqlserver.drop.sql +3 -0
  101. data/test/fixtures/db_definitions/sqlserver.sql +23 -3
  102. data/test/fixtures/db_definitions/sybase.drop.sql +31 -0
  103. data/test/fixtures/db_definitions/sybase.sql +204 -0
  104. data/test/fixtures/db_definitions/sybase2.drop.sql +4 -0
  105. data/test/fixtures/db_definitions/sybase2.sql +5 -0
  106. data/test/fixtures/developers.yml +6 -1
  107. data/test/fixtures/developers_projects.yml +4 -0
  108. data/test/fixtures/funny_jokes.yml +14 -0
  109. data/test/fixtures/joke.rb +6 -0
  110. data/test/fixtures/legacy_thing.rb +3 -0
  111. data/test/fixtures/legacy_things.yml +3 -0
  112. data/test/fixtures/mixin.rb +1 -1
  113. data/test/fixtures/person.rb +4 -1
  114. data/test/fixtures/post.rb +26 -1
  115. data/test/fixtures/project.rb +1 -0
  116. data/test/fixtures/reader.rb +4 -0
  117. data/test/fixtures/readers.yml +4 -0
  118. data/test/fixtures/reply.rb +2 -1
  119. data/test/fixtures/tag.rb +5 -0
  120. data/test/fixtures/tagging.rb +6 -0
  121. data/test/fixtures/taggings.yml +18 -0
  122. data/test/fixtures/tags.yml +7 -0
  123. data/test/fixtures/tasks.yml +2 -2
  124. data/test/fixtures/topic.rb +2 -2
  125. data/test/fixtures/topics.yml +1 -0
  126. data/test/fixtures_test.rb +47 -13
  127. data/test/inheritance_test.rb +2 -2
  128. data/test/locking_test.rb +15 -1
  129. data/test/method_scoping_test.rb +248 -13
  130. data/test/migration_test.rb +68 -11
  131. data/test/mixin_nested_set_test.rb +1 -1
  132. data/test/modules_test.rb +6 -1
  133. data/test/readonly_test.rb +1 -1
  134. data/test/reflection_test.rb +63 -9
  135. data/test/schema_dumper_test.rb +41 -0
  136. data/test/{synonym_test_oci.rb → synonym_test_oracle.rb} +1 -1
  137. data/test/threaded_connections_test.rb +10 -0
  138. data/test/unconnected_test.rb +12 -5
  139. data/test/validations_test.rb +197 -10
  140. metadata +295 -260
  141. data/test/fixtures/db_definitions/create_oracle_db.bat +0 -0
  142. data/test/fixtures/db_definitions/create_oracle_db.sh +0 -0
  143. data/test/fixtures/fixture_database.sqlite +0 -0
  144. data/test/fixtures/fixture_database_2.sqlite +0 -0
@@ -1,9 +1,15 @@
1
1
  class Category < ActiveRecord::Base
2
2
  has_and_belongs_to_many :posts
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'"
3
6
 
4
7
  def self.what_are_you
5
8
  'a category...'
6
9
  end
10
+
11
+ has_many :categorizations
12
+ has_many :authors, :through => :categorizations, :select => 'authors.*, categorizations.post_id'
7
13
  end
8
14
 
9
15
  class SpecialCategory < Category
@@ -3,17 +3,20 @@ class Company < ActiveRecord::Base
3
3
  set_sequence_name :companies_nonstd_seq
4
4
 
5
5
  validates_presence_of :name
6
+
7
+ has_one :dummy_account, :foreign_key => "firm_id", :class_name => "Account"
6
8
  end
7
9
 
8
10
 
9
11
  class Firm < Company
10
- has_many :clients, :order => "id", :dependent => true, :counter_sql =>
12
+ has_many :clients, :order => "id", :dependent => :destroy, :counter_sql =>
11
13
  "SELECT COUNT(*) FROM companies WHERE firm_id = 1 " +
12
14
  "AND (#{QUOTED_TYPE} = 'Client' OR #{QUOTED_TYPE} = 'SpecialClient' OR #{QUOTED_TYPE} = 'VerySpecialClient' )"
13
15
  has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
14
16
  has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
15
- has_many :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => true
16
- has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :exclusively_dependent => true
17
+ has_many :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :destroy
18
+ has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all
19
+ has_many :limited_clients, :class_name => "Client", :order => "id", :limit => 1
17
20
  has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
18
21
  has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
19
22
  has_many :clients_using_counter_sql, :class_name => "Client",
@@ -26,7 +29,7 @@ class Firm < Company
26
29
  :finder_sql => 'SELECT * FROM companies WHERE client_of = 1000',
27
30
  :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = 1000'
28
31
 
29
- has_one :account, :foreign_key => "firm_id", :dependent => true
32
+ has_one :account, :foreign_key => "firm_id", :dependent => :destroy
30
33
  end
31
34
 
32
35
  class DependentFirm < Company
@@ -39,7 +42,7 @@ class Client < Company
39
42
  belongs_to :firm, :foreign_key => "client_of"
40
43
  belongs_to :firm_with_basic_id, :class_name => "Firm", :foreign_key => "firm_id"
41
44
  belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of"
42
- belongs_to :firm_with_condition, :class_name => "Firm", :foreign_key => "client_of", :conditions => "1 = 1"
45
+ belongs_to :firm_with_condition, :class_name => "Firm", :foreign_key => "client_of", :conditions => ["1 = ?", 1]
43
46
 
44
47
  # Record destruction so we can test whether firm.clients.clear has
45
48
  # is calling client.destroy, deleting from the database, or setting
@@ -54,6 +57,15 @@ class Client < Company
54
57
  end
55
58
  true
56
59
  end
60
+
61
+ # Used to test that read and question methods are not generated for these attributes
62
+ def ruby_type
63
+ read_attribute :ruby_type
64
+ end
65
+
66
+ def rating?
67
+ query_attribute :rating
68
+ end
57
69
  end
58
70
 
59
71
 
@@ -5,13 +5,13 @@ module MyApplication
5
5
  end
6
6
 
7
7
  class Firm < Company
8
- has_many :clients, :order => "id", :dependent => true
8
+ has_many :clients, :order => "id", :dependent => :destroy
9
9
  has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
10
10
  has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
11
11
  has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id"
12
12
  has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}'
13
13
 
14
- has_one :account, :dependent => true
14
+ has_one :account, :dependent => :destroy
15
15
  end
16
16
 
17
17
  class Client < Company
@@ -33,11 +33,25 @@ module MyApplication
33
33
  end
34
34
 
35
35
  end
36
-
36
+
37
37
  module Billing
38
+ class Firm < ActiveRecord::Base
39
+ self.table_name = 'companies'
40
+ end
41
+
42
+ module Nested
43
+ class Firm < ActiveRecord::Base
44
+ self.table_name = 'companies'
45
+ end
46
+ end
47
+
38
48
  class Account < ActiveRecord::Base
39
- belongs_to :firm, :class_name => "MyApplication::Business::Firm"
40
-
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'
54
+
41
55
  protected
42
56
  def validate
43
57
  errors.add_on_empty "credit_limit"
@@ -1,4 +1,5 @@
1
1
  DROP TABLE accounts;
2
+ DROP TABLE funny_jokes;
2
3
  DROP TABLE companies;
3
4
  DROP TABLE topics;
4
5
  DROP TABLE developers;
@@ -14,6 +15,7 @@ DROP TABLE entrants;
14
15
  DROP TABLE colnametests;
15
16
  DROP TABLE mixins;
16
17
  DROP TABLE people;
18
+ DROP TABLE readers;
17
19
  DROP TABLE binaries;
18
20
  DROP TABLE computers;
19
21
  DROP TABLE posts;
@@ -25,3 +27,4 @@ DROP TABLE categories_posts;
25
27
  DROP TABLE fk_test_has_pk;
26
28
  DROP TABLE fk_test_has_fk;
27
29
  DROP TABLE keyboards;
30
+ DROP TABLE legacy_things;
@@ -1,196 +1,217 @@
1
1
  CREATE TABLE accounts (
2
- id int generated by default as identity (start with +10000),
3
- firm_id int default NULL,
4
- credit_limit int default NULL,
2
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
3
+ firm_id INT DEFAULT NULL,
4
+ credit_limit INT DEFAULT NULL,
5
+ PRIMARY KEY (id)
6
+ );
7
+
8
+ CREATE TABLE funny_jokes (
9
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
10
+ name VARCHAR(50) DEFAULT NULL,
5
11
  PRIMARY KEY (id)
6
12
  );
7
13
 
8
14
  CREATE TABLE companies (
9
- id int generated by default as identity (start with +10000),
10
- type varchar(50) default NULL,
11
- ruby_type varchar(50) default NULL,
12
- firm_id int default NULL,
13
- name varchar(50) default NULL,
14
- client_of int default NULL,
15
- rating int default 1,
15
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
16
+ type VARCHAR(50) DEFAULT NULL,
17
+ ruby_type VARCHAR(50) DEFAULT NULL,
18
+ firm_id INT DEFAULT NULL,
19
+ name VARCHAR(50) DEFAULT NULL,
20
+ client_of INT DEFAULT NULL,
21
+ rating INT DEFAULT 1,
16
22
  PRIMARY KEY (id)
17
23
  );
18
24
 
19
25
  CREATE TABLE topics (
20
- id int generated by default as identity (start with +10000),
21
- title varchar(255) default NULL,
22
- author_name varchar(255) default NULL,
23
- author_email_address varchar(255) default NULL,
24
- written_on timestamp default NULL,
25
- bonus_time time default NULL,
26
- last_read date default NULL,
27
- content varchar(3000),
28
- approved smallint default 1,
29
- replies_count int default 0,
30
- parent_id int default NULL,
31
- type varchar(50) default NULL,
26
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
27
+ title VARCHAR(255) DEFAULT NULL,
28
+ author_name VARCHAR(255) DEFAULT NULL,
29
+ author_email_address VARCHAR(255) DEFAULT NULL,
30
+ written_on TIMESTAMP DEFAULT NULL,
31
+ bonus_time TIME DEFAULT NULL,
32
+ last_read DATE DEFAULT NULL,
33
+ content VARCHAR(3000),
34
+ approved SMALLINT DEFAULT 1,
35
+ replies_count INT DEFAULT 0,
36
+ parent_id INT DEFAULT NULL,
37
+ type VARCHAR(50) DEFAULT NULL,
32
38
  PRIMARY KEY (id)
33
39
  );
34
40
 
35
41
  CREATE TABLE developers (
36
- id int generated by default as identity (start with +10000),
37
- name varchar(100) default NULL,
38
- salary int default 70000,
39
- created_at timestamp default NULL,
40
- updated_at timestamp default NULL,
42
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
43
+ name VARCHAR(100) DEFAULT NULL,
44
+ salary INT DEFAULT 70000,
45
+ created_at TIMESTAMP DEFAULT NULL,
46
+ updated_at TIMESTAMP DEFAULT NULL,
41
47
  PRIMARY KEY (id)
42
48
  );
43
49
 
44
50
  CREATE TABLE projects (
45
- id int generated by default as identity (start with +10000),
46
- name varchar(100) default NULL,
47
- type varchar(255) default NULL,
51
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
52
+ name VARCHAR(100) DEFAULT NULL,
53
+ type VARCHAR(255) DEFAULT NULL,
48
54
  PRIMARY KEY (id)
49
55
  );
50
56
 
51
57
  CREATE TABLE developers_projects (
52
- developer_id int NOT NULL,
53
- project_id int NOT NULL,
54
- joined_on date default NULL,
55
- access_level smallint default 1
58
+ developer_id INT NOT NULL,
59
+ project_id INT NOT NULL,
60
+ joined_on DATE DEFAULT NULL,
61
+ access_level SMALLINT DEFAULT 1
56
62
  );
57
63
 
58
64
  CREATE TABLE orders (
59
- id int generated by default as identity (start with +10000),
60
- name varchar(100) default NULL,
61
- billing_customer_id int default NULL,
62
- shipping_customer_id int default NULL,
65
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
66
+ name VARCHAR(100) DEFAULT NULL,
67
+ billing_customer_id INT DEFAULT NULL,
68
+ shipping_customer_id INT DEFAULT NULL,
63
69
  PRIMARY KEY (id)
64
70
  );
65
71
 
66
72
  CREATE TABLE customers (
67
- id int generated by default as identity (start with +10000),
68
- name varchar(100) default NULL,
69
- balance int default 0,
70
- address_street varchar(100) default NULL,
71
- address_city varchar(100) default NULL,
72
- address_country varchar(100) default NULL,
73
- gps_location varchar(100) default NULL,
73
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
74
+ name VARCHAR(100) DEFAULT NULL,
75
+ balance INT DEFAULT 0,
76
+ address_street VARCHAR(100) DEFAULT NULL,
77
+ address_city VARCHAR(100) DEFAULT NULL,
78
+ address_country VARCHAR(100) DEFAULT NULL,
79
+ gps_location VARCHAR(100) DEFAULT NULL,
74
80
  PRIMARY KEY (id)
75
81
  );
76
82
 
77
83
  CREATE TABLE movies (
78
- movieid int generated by default as identity (start with +10000),
79
- name varchar(100) default NULL,
84
+ movieid INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
85
+ name VARCHAR(100) DEFAULT NULL,
80
86
  PRIMARY KEY (movieid)
81
87
  );
82
88
 
83
89
  CREATE TABLE subscribers (
84
- nick varchar(100) NOT NULL,
85
- name varchar(100) default NULL,
90
+ nick VARCHAR(100) NOT NULL,
91
+ name VARCHAR(100) DEFAULT NULL,
86
92
  PRIMARY KEY (nick)
87
93
  );
88
94
 
89
95
  CREATE TABLE booleantests (
90
- id int generated by default as identity (start with +10000),
91
- value int default NULL,
96
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
97
+ value INT DEFAULT NULL,
92
98
  PRIMARY KEY (id)
93
99
  );
94
100
 
95
101
  CREATE TABLE auto_id_tests (
96
- auto_id int generated by default as identity (start with +10000),
97
- value int default NULL,
102
+ auto_id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
103
+ value INT DEFAULT NULL,
98
104
  PRIMARY KEY (auto_id)
99
105
  );
100
106
 
101
107
  CREATE TABLE entrants (
102
- id int NOT NULL PRIMARY KEY,
103
- name varchar(255) NOT NULL,
104
- course_id int NOT NULL
108
+ id INT NOT NULL PRIMARY KEY,
109
+ name VARCHAR(255) NOT NULL,
110
+ course_id INT NOT NULL
105
111
  );
106
112
 
107
113
  CREATE TABLE colnametests (
108
- id int generated by default as identity (start with +10000),
109
- references int NOT NULL,
114
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
115
+ references INT NOT NULL,
110
116
  PRIMARY KEY (id)
111
117
  );
112
118
 
113
119
  CREATE TABLE mixins (
114
- id int generated by default as identity (start with +10000),
115
- parent_id int default NULL,
116
- pos int default NULL,
117
- created_at timestamp default NULL,
118
- updated_at timestamp default NULL,
119
- lft int default NULL,
120
- rgt int default NULL,
121
- root_id int default NULL,
122
- type varchar(40) default NULL,
120
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
121
+ parent_id INT DEFAULT NULL,
122
+ pos INT DEFAULT NULL,
123
+ created_at TIMESTAMP DEFAULT NULL,
124
+ updated_at TIMESTAMP DEFAULT NULL,
125
+ lft INT DEFAULT NULL,
126
+ rgt INT DEFAULT NULL,
127
+ root_id INT DEFAULT NULL,
128
+ type VARCHAR(40) DEFAULT NULL,
123
129
  PRIMARY KEY (id)
124
130
  );
125
131
 
126
132
  CREATE TABLE people (
127
- id int generated by default as identity (start with +10000),
128
- first_name varchar(40) NOT NULL,
129
- lock_version int default 0,
130
- PRIMARY KEY (id)
133
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
134
+ first_name VARCHAR(40) NOT NULL,
135
+ lock_version INT DEFAULT 0,
136
+ PRIMARY KEY (id)
137
+ );
138
+
139
+ CREATE TABLE readers (
140
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
141
+ post_id INT NOT NULL,
142
+ person_id INT NOT NULL,
143
+ PRIMARY KEY (id)
131
144
  );
132
145
 
133
146
  CREATE TABLE binaries (
134
- id int generated by default as identity (start with +10000),
135
- data blob(50000),
136
- PRIMARY KEY (id)
147
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
148
+ data BLOB(50000),
149
+ PRIMARY KEY (id)
137
150
  );
138
151
 
139
152
  CREATE TABLE computers (
140
- id int generated by default as identity (start with +10000),
141
- developer int NOT NULL,
142
- extendedWarranty int NOT NULL
153
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
154
+ developer INT NOT NULL,
155
+ extendedWarranty INT NOT NULL
143
156
  );
144
157
 
145
158
  CREATE TABLE posts (
146
- id int generated by default as identity (start with +10000),
147
- author_id int default NULL,
148
- title varchar(255) default NULL,
149
- type varchar(255) default NULL,
150
- body varchar(3000) default NULL
159
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
160
+ author_id INT DEFAULT NULL,
161
+ title VARCHAR(255) DEFAULT NULL,
162
+ type VARCHAR(255) DEFAULT NULL,
163
+ body VARCHAR(3000) DEFAULT NULL
151
164
  );
152
165
 
153
166
  CREATE TABLE comments (
154
- id int generated by default as identity (start with +10000),
155
- post_id int default NULL,
156
- type varchar(255) default NULL,
157
- body varchar(3000) default NULL
167
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
168
+ post_id INT DEFAULT NULL,
169
+ type VARCHAR(255) DEFAULT NULL,
170
+ body VARCHAR(3000) DEFAULT NULL
158
171
  );
159
172
 
160
173
  CREATE TABLE authors (
161
- id int generated by default as identity (start with +10000),
162
- name varchar(255) default NULL
174
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
175
+ name VARCHAR(255) DEFAULT NULL
163
176
  );
164
177
 
165
178
  CREATE TABLE tasks (
166
- id int generated by default as identity (start with +10000),
167
- starting timestamp default NULL,
168
- ending timestamp default NULL
179
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
180
+ starting TIMESTAMP DEFAULT NULL,
181
+ ending TIMESTAMP DEFAULT NULL
169
182
  );
170
183
 
171
184
  CREATE TABLE categories (
172
- id int generated by default as identity (start with +10000),
173
- name varchar(255) NOT NULL,
174
- type varchar(40) default NULL
185
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
186
+ name VARCHAR(255) NOT NULL,
187
+ type VARCHAR(40) DEFAULT NULL
175
188
  );
176
189
 
177
190
  CREATE TABLE categories_posts (
178
- category_id int NOT NULL,
179
- post_id int NOT NULL
191
+ category_id INT NOT NULL,
192
+ post_id INT NOT NULL
180
193
  );
181
194
 
182
195
  CREATE TABLE keyboards (
183
- key_number int generated by default as identity (start with +10000),
196
+ key_number INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
184
197
  name VARCHAR(255)
185
198
  );
186
199
 
187
200
  CREATE TABLE fk_test_has_pk (
188
- id INTEGER NOT NULL PRIMARY KEY
201
+ id INT NOT NULL PRIMARY KEY
189
202
  );
190
203
 
191
204
  CREATE TABLE fk_test_has_fk (
192
- id INTEGER NOT NULL PRIMARY KEY,
193
- fk_id INTEGER NOT NULL,
205
+ id INT NOT NULL PRIMARY KEY,
206
+ fk_id INT NOT NULL,
194
207
 
195
208
  FOREIGN KEY (fk_id) REFERENCES fk_test_has_pk(id)
196
209
  );
210
+
211
+ --This table has an altered lock_version column name
212
+ CREATE TABLE legacy_things (
213
+ id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000),
214
+ tps_report_number INT DEFAULT NULL,
215
+ version INT DEFAULT 0,
216
+ PRIMARY KEY (id)
217
+ );