composite_primary_keys 8.1.6 → 9.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.rdoc +59 -7
- data/README.rdoc +62 -1
- data/Rakefile +4 -1
- data/lib/composite_primary_keys/arel/in.rb +6 -0
- data/lib/composite_primary_keys/arel/sqlserver.rb +36 -0
- data/lib/composite_primary_keys/arel/to_sql.rb +26 -0
- data/lib/composite_primary_keys/associations/association.rb +14 -12
- data/lib/composite_primary_keys/associations/association_scope.rb +22 -27
- data/lib/composite_primary_keys/associations/collection_association.rb +39 -8
- data/lib/composite_primary_keys/associations/has_many_association.rb +17 -40
- data/lib/composite_primary_keys/associations/has_many_through_association.rb +58 -58
- data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +13 -11
- data/lib/composite_primary_keys/associations/join_dependency.rb +73 -56
- data/lib/composite_primary_keys/associations/preloader/association.rb +75 -73
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +13 -11
- data/lib/composite_primary_keys/attribute_methods/read.rb +18 -15
- data/lib/composite_primary_keys/attribute_methods/write.rb +21 -19
- data/lib/composite_primary_keys/attribute_methods.rb +6 -4
- data/lib/composite_primary_keys/autosave_association.rb +19 -54
- data/lib/composite_primary_keys/base.rb +18 -82
- data/lib/composite_primary_keys/composite_arrays.rb +9 -1
- data/lib/composite_primary_keys/composite_predicates.rb +1 -0
- data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
- data/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb +5 -6
- data/lib/composite_primary_keys/connection_adapters/sqlite3_adapter.rb +23 -0
- data/lib/composite_primary_keys/core.rb +46 -45
- data/lib/composite_primary_keys/fixtures.rb +19 -17
- data/lib/composite_primary_keys/locking/optimistic.rb +53 -49
- data/lib/composite_primary_keys/nested_attributes.rb +60 -53
- data/lib/composite_primary_keys/persistence.rb +49 -41
- data/lib/composite_primary_keys/relation/batches.rb +35 -32
- data/lib/composite_primary_keys/relation/calculations.rb +3 -7
- data/lib/composite_primary_keys/relation/finder_methods.rb +122 -55
- data/lib/composite_primary_keys/relation/predicate_builder.rb +18 -29
- data/lib/composite_primary_keys/relation/query_methods.rb +25 -36
- data/lib/composite_primary_keys/relation/where_clause.rb +33 -0
- data/lib/composite_primary_keys/relation.rb +96 -43
- data/lib/composite_primary_keys/sanitization.rb +6 -15
- data/lib/composite_primary_keys/version.rb +3 -3
- data/lib/composite_primary_keys.rb +10 -19
- data/scripts/console.rb +48 -48
- data/scripts/txt2html +76 -76
- data/scripts/txt2js +65 -65
- data/tasks/databases/mysql.rake +17 -19
- data/tasks/databases/oracle.rake +29 -15
- data/tasks/databases/postgresql.rake +20 -29
- data/tasks/databases/sqlite.rake +25 -0
- data/tasks/databases/sqlserver.rake +32 -16
- data/tasks/website.rake +18 -18
- data/test/README_tests.rdoc +56 -56
- data/test/abstract_unit.rb +24 -18
- data/test/connections/connection_spec.rb +11 -2
- data/test/connections/databases.ci.yml +5 -4
- data/test/connections/databases.example.yml +19 -4
- data/test/connections/databases.yml +40 -30
- data/test/db_test.rb +52 -52
- data/test/fixtures/article.rb +1 -0
- data/test/fixtures/articles.yml +6 -6
- data/test/fixtures/capitol.rb +3 -3
- data/test/fixtures/capitols.yml +16 -16
- data/test/fixtures/comments.yml +15 -15
- data/test/fixtures/db_definitions/mysql.sql +16 -17
- data/test/fixtures/db_definitions/oracle.drop.sql +2 -0
- data/test/fixtures/db_definitions/oracle.sql +26 -17
- data/test/fixtures/db_definitions/postgresql.sql +2 -3
- data/test/fixtures/db_definitions/sqlite.sql +0 -1
- data/test/fixtures/db_definitions/sqlserver.sql +20 -35
- data/test/fixtures/department.rb +5 -5
- data/test/fixtures/departments.yml +15 -15
- data/test/fixtures/dorms.yml +4 -4
- data/test/fixtures/employee.rb +5 -7
- data/test/fixtures/employees.yml +1 -5
- data/test/fixtures/group.rb +2 -2
- data/test/fixtures/groups.yml +6 -6
- data/test/fixtures/hack.rb +4 -4
- data/test/fixtures/hacks.yml +2 -2
- data/test/fixtures/membership_status.rb +2 -2
- data/test/fixtures/product.rb +9 -9
- data/test/fixtures/product_tariff.rb +5 -5
- data/test/fixtures/products.yml +11 -11
- data/test/fixtures/reading.rb +4 -4
- data/test/fixtures/readings.yml +10 -10
- data/test/fixtures/reference_code_using_composite_key_alias.rb +8 -8
- data/test/fixtures/reference_code_using_simple_key_alias.rb +8 -8
- data/test/fixtures/reference_codes.yml +28 -28
- data/test/fixtures/reference_type.rb +1 -1
- data/test/fixtures/reference_types.yml +9 -9
- data/test/fixtures/restaurant.rb +9 -9
- data/test/fixtures/restaurants.yml +14 -14
- data/test/fixtures/restaurants_suburbs.yml +10 -10
- data/test/fixtures/room.rb +11 -11
- data/test/fixtures/room_assignment.rb +13 -13
- data/test/fixtures/room_assignments.yml +24 -24
- data/test/fixtures/room_attribute.rb +2 -2
- data/test/fixtures/room_attribute_assignment.rb +4 -4
- data/test/fixtures/room_attribute_assignments.yml +4 -4
- data/test/fixtures/room_attributes.yml +2 -2
- data/test/fixtures/rooms.yml +12 -12
- data/test/fixtures/seat.rb +5 -5
- data/test/fixtures/seats.yml +8 -8
- data/test/fixtures/street.rb +2 -2
- data/test/fixtures/streets.yml +16 -16
- data/test/fixtures/student.rb +3 -3
- data/test/fixtures/students.yml +15 -15
- data/test/fixtures/suburbs.yml +14 -14
- data/test/fixtures/tariff.rb +1 -1
- data/test/fixtures/tariffs.yml +14 -14
- data/test/fixtures/user.rb +0 -1
- data/test/plugins/pagination.rb +405 -405
- data/test/plugins/pagination_helper.rb +135 -135
- data/test/setup.rb +50 -50
- data/test/test_aliases.rb +18 -18
- data/test/test_associations.rb +18 -17
- data/test/test_composite_arrays.rb +24 -24
- data/test/test_counter_cache.rb +30 -30
- data/test/test_create.rb +14 -6
- data/test/test_delete.rb +36 -34
- data/test/test_dup.rb +37 -37
- data/test/test_exists.rb +39 -39
- data/test/test_find.rb +16 -4
- data/test/test_habtm.rb +27 -3
- data/test/test_miscellaneous.rb +32 -32
- data/test/test_nested_attributes.rb +6 -6
- data/test/test_pagination.rb +35 -35
- data/test/test_polymorphic.rb +0 -7
- data/test/test_predicates.rb +20 -20
- data/test/test_preload.rb +94 -0
- data/test/test_suite.rb +1 -1
- data/test/test_update.rb +10 -7
- data/test/test_validations.rb +13 -13
- metadata +30 -39
- data/README_DB2.rdoc +0 -33
- data/lib/composite_primary_keys/arel/visitors/to_sql.rb +0 -36
- data/lib/composite_primary_keys/associations/singular_association.rb +0 -18
- data/lib/composite_primary_keys/attribute_methods/dirty.rb +0 -29
- data/lib/composite_primary_keys/attribute_set/builder.rb +0 -20
- data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +0 -70
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +0 -19
- data/lib/composite_primary_keys/dirty.rb +0 -19
- data/lib/composite_primary_keys/validations/uniqueness.rb +0 -41
- data/tasks/databases/oracle_enhanced.rake +0 -27
- data/tasks/databases/sqlite3.rake +0 -27
- data/test/connections/native_ibm_db/connection.rb +0 -19
- data/test/connections/native_mysql/connection.rb +0 -17
- data/test/connections/native_oracle/connection.rb +0 -11
- data/test/connections/native_oracle_enhanced/connection.rb +0 -16
- data/test/connections/native_postgresql/connection.rb +0 -13
- data/test/connections/native_sqlite3/connection.rb +0 -9
- data/test/connections/native_sqlserver/connection.rb +0 -11
- data/test/fixtures/db_definitions/sqlserver.drop.sql +0 -92
- data/test/test_delete_all.rb +0 -35
- data/test/test_find_in_batches.rb +0 -30
@@ -1,17 +1,26 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'erb'
|
2
3
|
|
3
4
|
module CompositePrimaryKeys
|
4
5
|
class ConnectionSpec
|
5
6
|
def self.[](adapter)
|
6
|
-
config[adapter.to_s]
|
7
|
+
config[adapter.to_s].dup
|
7
8
|
end
|
8
9
|
|
9
10
|
private
|
10
11
|
|
11
12
|
def self.config
|
12
13
|
@config ||= begin
|
14
|
+
# Find the file location
|
13
15
|
path = File.join(PROJECT_ROOT, 'test', 'connections', 'databases.yml')
|
14
|
-
|
16
|
+
|
17
|
+
# Run any erb code
|
18
|
+
template = ERB.new(File.read(path))
|
19
|
+
project_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
20
|
+
data = template.result(binding)
|
21
|
+
|
22
|
+
# And now to YAML
|
23
|
+
YAML.load(data)
|
15
24
|
end
|
16
25
|
end
|
17
26
|
end
|
@@ -4,12 +4,13 @@ mysql:
|
|
4
4
|
password: ""
|
5
5
|
database: composite_primary_keys_unittest
|
6
6
|
|
7
|
-
sqlite3:
|
8
|
-
adapter: sqlite3
|
9
|
-
database: db/composite_primary_keys_unittest.sqlite
|
10
|
-
|
11
7
|
postgresql:
|
12
8
|
adapter: postgresql
|
13
9
|
database: composite_primary_keys_unittest
|
14
10
|
username: postgres
|
15
11
|
host: localhost
|
12
|
+
|
13
|
+
sqlite:
|
14
|
+
adapter: sqlite3
|
15
|
+
database: <%= File.join(project_root, 'db', 'composite_primary_keys_unittest.sqlite') %>
|
16
|
+
|
@@ -2,14 +2,24 @@
|
|
2
2
|
# 1. Copy this file to test/connections/databases.yml.
|
3
3
|
# 2. Update to match the databases you want to test against.
|
4
4
|
|
5
|
+
ibm_db:
|
6
|
+
database: ocdpdev
|
7
|
+
username: db2inst1
|
8
|
+
password: password
|
9
|
+
host: localhost
|
10
|
+
|
5
11
|
mysql:
|
6
12
|
adapter: mysql2
|
7
13
|
username: root
|
14
|
+
password: mysql
|
8
15
|
database: composite_primary_keys_unittest
|
9
16
|
|
10
|
-
|
11
|
-
adapter:
|
12
|
-
database:
|
17
|
+
oracle:
|
18
|
+
adapter: oracle_enhanced
|
19
|
+
database: xe
|
20
|
+
username: SYSTEM
|
21
|
+
password: oracle
|
22
|
+
host: localhost
|
13
23
|
|
14
24
|
postgresql:
|
15
25
|
adapter: postgresql
|
@@ -17,9 +27,14 @@ postgresql:
|
|
17
27
|
username: postgres
|
18
28
|
host: localhost
|
19
29
|
|
30
|
+
sqlite:
|
31
|
+
adapter: sqlite3
|
32
|
+
database: <%= File.join(project_root, 'db', 'composite_primary_keys_unittest.sqlite') %>
|
33
|
+
|
20
34
|
sqlserver:
|
21
35
|
adapter: sqlserver
|
36
|
+
username: cpk
|
37
|
+
password: cpk
|
22
38
|
database: composite_primary_keys_unittest
|
23
|
-
username: rails
|
24
39
|
host: localhost
|
25
40
|
port: 1433
|
@@ -1,30 +1,40 @@
|
|
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
|
-
adapter:
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
1
|
+
# To run tests:
|
2
|
+
# 1. Copy this file to test/connections/databases.yml.
|
3
|
+
# 2. Update to match the databases you want to test against.
|
4
|
+
|
5
|
+
ibm_db:
|
6
|
+
database: ocdpdev
|
7
|
+
username: db2inst1
|
8
|
+
password: password
|
9
|
+
host: localhost
|
10
|
+
|
11
|
+
mysql:
|
12
|
+
adapter: mysql2
|
13
|
+
username: root
|
14
|
+
password: mysql
|
15
|
+
database: composite_primary_keys_unittest
|
16
|
+
|
17
|
+
oracle:
|
18
|
+
adapter: oracle_enhanced
|
19
|
+
database: xe
|
20
|
+
username: SYSTEM
|
21
|
+
password: oracle
|
22
|
+
host: localhost
|
23
|
+
|
24
|
+
postgresql:
|
25
|
+
adapter: postgresql
|
26
|
+
database: composite_primary_keys_unittest
|
27
|
+
username: postgres
|
28
|
+
host: localhost
|
29
|
+
|
30
|
+
sqlite:
|
31
|
+
adapter: sqlite3
|
32
|
+
database: <%= File.join(project_root, 'db', 'composite_primary_keys_unittest.sqlite') %>
|
33
|
+
|
34
|
+
sqlserver:
|
35
|
+
adapter: sqlserver
|
36
|
+
username: cpk
|
37
|
+
password: cpk
|
38
|
+
database: composite_primary_keys_unittest
|
39
|
+
host: localhost
|
40
|
+
port: 1433
|
data/test/db_test.rb
CHANGED
@@ -1,53 +1,53 @@
|
|
1
|
-
# assoc_test.rb
|
2
|
-
|
3
|
-
path = File.expand_path(File.join(File.basename(__FILE__), "..", "lib", "composite_primary_keys"))
|
4
|
-
puts path
|
5
|
-
|
6
|
-
require File.join(path)
|
7
|
-
require 'active_record'
|
8
|
-
|
9
|
-
$configuration = {
|
10
|
-
:adapter => 'postgresql',
|
11
|
-
:database => 'cpk_test',
|
12
|
-
:username => 'postgres'
|
13
|
-
}
|
14
|
-
|
15
|
-
ActiveRecord::Base.establish_connection($configuration) unless ActiveRecord::Base.connected?
|
16
|
-
|
17
|
-
module GlobePG
|
18
|
-
class PGBase < ActiveRecord::Base
|
19
|
-
self.abstract_class = true
|
20
|
-
# establish_connection($configuration) unless connected?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module GlobePG
|
25
|
-
class TeacherToSchool < PGBase
|
26
|
-
set_table_name 'teacher_to_school'
|
27
|
-
self.primary_keys = ['teacherid', 'schoolid']
|
28
|
-
|
29
|
-
belongs_to :globe_teacher, :foreign_key => 'teacherid'
|
30
|
-
belongs_to :globe_school, :foreign_key => 'schoolid'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
module GlobePG
|
35
|
-
class GlobeSchool < PGBase
|
36
|
-
set_table_name 'globe_school'
|
37
|
-
self.primary_key = 'schoolid'
|
38
|
-
has_many :teacher_to_schools, :foreign_key => :schoolid
|
39
|
-
has_many :globe_teachers, :through => :teacher_to_schools
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
module GlobePG
|
44
|
-
class GlobeTeacher < PGBase
|
45
|
-
set_table_name 'globe_teacher'
|
46
|
-
self.primary_key = 'teacherid'
|
47
|
-
has_many :teacher_to_schools, :foreign_key => :teacherid
|
48
|
-
has_many :globe_schools, :through => :teacher_to_schools
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
teacher = GlobePG::GlobeTeacher.find_by_teacherid('ZZGLOBEY')
|
1
|
+
# assoc_test.rb
|
2
|
+
|
3
|
+
path = File.expand_path(File.join(File.basename(__FILE__), "..", "lib", "composite_primary_keys"))
|
4
|
+
puts path
|
5
|
+
|
6
|
+
require File.join(path)
|
7
|
+
require 'active_record'
|
8
|
+
|
9
|
+
$configuration = {
|
10
|
+
:adapter => 'postgresql',
|
11
|
+
:database => 'cpk_test',
|
12
|
+
:username => 'postgres'
|
13
|
+
}
|
14
|
+
|
15
|
+
ActiveRecord::Base.establish_connection($configuration) unless ActiveRecord::Base.connected?
|
16
|
+
|
17
|
+
module GlobePG
|
18
|
+
class PGBase < ActiveRecord::Base
|
19
|
+
self.abstract_class = true
|
20
|
+
# establish_connection($configuration) unless connected?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module GlobePG
|
25
|
+
class TeacherToSchool < PGBase
|
26
|
+
set_table_name 'teacher_to_school'
|
27
|
+
self.primary_keys = ['teacherid', 'schoolid']
|
28
|
+
|
29
|
+
belongs_to :globe_teacher, :foreign_key => 'teacherid'
|
30
|
+
belongs_to :globe_school, :foreign_key => 'schoolid'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module GlobePG
|
35
|
+
class GlobeSchool < PGBase
|
36
|
+
set_table_name 'globe_school'
|
37
|
+
self.primary_key = 'schoolid'
|
38
|
+
has_many :teacher_to_schools, :foreign_key => :schoolid
|
39
|
+
has_many :globe_teachers, :through => :teacher_to_schools
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module GlobePG
|
44
|
+
class GlobeTeacher < PGBase
|
45
|
+
set_table_name 'globe_teacher'
|
46
|
+
self.primary_key = 'teacherid'
|
47
|
+
has_many :teacher_to_schools, :foreign_key => :teacherid
|
48
|
+
has_many :globe_schools, :through => :teacher_to_schools
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
teacher = GlobePG::GlobeTeacher.find_by_teacherid('ZZGLOBEY')
|
53
53
|
p teacher.globe_schools
|
data/test/fixtures/article.rb
CHANGED
data/test/fixtures/articles.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
first:
|
2
|
-
id: 1
|
3
|
-
name: Article One
|
4
|
-
|
5
|
-
second:
|
6
|
-
id: 2
|
1
|
+
first:
|
2
|
+
id: 1
|
3
|
+
name: Article One
|
4
|
+
|
5
|
+
second:
|
6
|
+
id: 2
|
7
7
|
name: Article Two
|
data/test/fixtures/capitol.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
class Capitol < ActiveRecord::Base
|
2
|
-
self.primary_keys = :country, :city
|
3
|
-
end
|
1
|
+
class Capitol < ActiveRecord::Base
|
2
|
+
self.primary_keys = :country, :city
|
3
|
+
end
|
data/test/fixtures/capitols.yml
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
netherlands:
|
2
|
-
country: The Netherlands
|
3
|
-
city: Amsterdam
|
4
|
-
|
5
|
-
france:
|
6
|
-
country: France
|
7
|
-
city: Paris
|
8
|
-
|
9
|
-
canada:
|
10
|
-
country: Canada
|
11
|
-
city: Ottawa
|
12
|
-
|
13
|
-
mexico:
|
14
|
-
country: Mexico
|
15
|
-
city: Mexico City
|
16
|
-
|
1
|
+
netherlands:
|
2
|
+
country: The Netherlands
|
3
|
+
city: Amsterdam
|
4
|
+
|
5
|
+
france:
|
6
|
+
country: France
|
7
|
+
city: Paris
|
8
|
+
|
9
|
+
canada:
|
10
|
+
country: Canada
|
11
|
+
city: Ottawa
|
12
|
+
|
13
|
+
mexico:
|
14
|
+
country: Mexico
|
15
|
+
city: Mexico City
|
16
|
+
|
data/test/fixtures/comments.yml
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
comment1:
|
2
|
-
id: 1
|
3
|
-
person_id: 1
|
4
|
-
person_type: Employee
|
5
|
-
|
6
|
-
comment2:
|
7
|
-
id: 2
|
8
|
-
person_id: 1
|
9
|
-
person_type: User
|
10
|
-
hack_id: 7
|
11
|
-
|
12
|
-
comment3:
|
13
|
-
id: 3
|
14
|
-
person_id: 7
|
15
|
-
person_type: Hack
|
1
|
+
comment1:
|
2
|
+
id: 1
|
3
|
+
person_id: 1
|
4
|
+
person_type: Employee
|
5
|
+
|
6
|
+
comment2:
|
7
|
+
id: 2
|
8
|
+
person_id: 1
|
9
|
+
person_type: User
|
10
|
+
hack_id: 7
|
11
|
+
|
12
|
+
comment3:
|
13
|
+
id: 3
|
14
|
+
person_id: 7
|
15
|
+
person_type: Hack
|
16
16
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
create table topics (
|
2
|
-
id int not null auto_increment,
|
2
|
+
id int not null auto_increment,
|
3
3
|
name varchar(50) default null,
|
4
4
|
feed_size int default null,
|
5
5
|
primary key (id)
|
@@ -39,8 +39,8 @@ create table tariffs (
|
|
39
39
|
tariff_id int not null,
|
40
40
|
start_date date not null,
|
41
41
|
amount integer(11) default null,
|
42
|
-
created_at
|
43
|
-
updated_at
|
42
|
+
created_at datetime,
|
43
|
+
updated_at datetime,
|
44
44
|
primary key (tariff_id, start_date)
|
45
45
|
);
|
46
46
|
|
@@ -116,7 +116,6 @@ create table employees (
|
|
116
116
|
id int not null auto_increment,
|
117
117
|
department_id int default null,
|
118
118
|
location_id int default null,
|
119
|
-
name varchar(100) not null default 'anonymous',
|
120
119
|
primary key (id)
|
121
120
|
);
|
122
121
|
|
@@ -156,8 +155,8 @@ create table restaurants (
|
|
156
155
|
create table restaurants_suburbs (
|
157
156
|
franchise_id int not null,
|
158
157
|
store_id int not null,
|
159
|
-
city_id int
|
160
|
-
suburb_id int
|
158
|
+
city_id int default null,
|
159
|
+
suburb_id int default null
|
161
160
|
);
|
162
161
|
|
163
162
|
create table dorms (
|
@@ -202,15 +201,15 @@ create table seats (
|
|
202
201
|
);
|
203
202
|
|
204
203
|
create table capitols (
|
205
|
-
country varchar(100)
|
206
|
-
city varchar(100)
|
204
|
+
country varchar(100) not null,
|
205
|
+
city varchar(100) not null,
|
207
206
|
primary key (country, city)
|
208
207
|
);
|
209
208
|
|
210
209
|
create table products_restaurants (
|
211
210
|
product_id int not null,
|
212
|
-
franchise_id int
|
213
|
-
store_id int
|
211
|
+
franchise_id int default null,
|
212
|
+
store_id int default null
|
214
213
|
);
|
215
214
|
|
216
215
|
create table employees_groups (
|
@@ -219,10 +218,10 @@ create table employees_groups (
|
|
219
218
|
);
|
220
219
|
|
221
220
|
create table pk_called_ids (
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
);
|
221
|
+
id integer not null,
|
222
|
+
reference_code int not null,
|
223
|
+
code_label varchar(50) default null,
|
224
|
+
abbreviation varchar(50) default null,
|
225
|
+
description varchar(50) default null,
|
226
|
+
primary key (id, reference_code)
|
227
|
+
);
|
@@ -16,24 +16,24 @@ create sequence reference_types_seq start with 1000;
|
|
16
16
|
|
17
17
|
create table reference_types (
|
18
18
|
reference_type_id number(11) primary key,
|
19
|
-
type_label
|
20
|
-
abbreviation
|
21
|
-
description
|
19
|
+
type_label varchar(50) default null,
|
20
|
+
abbreviation varchar(50) default null,
|
21
|
+
description varchar(50) default null
|
22
22
|
);
|
23
23
|
|
24
24
|
create table reference_codes (
|
25
25
|
reference_type_id number(11),
|
26
26
|
reference_code number(11),
|
27
|
-
code_label
|
28
|
-
abbreviation
|
29
|
-
description
|
27
|
+
code_label varchar(50) default null,
|
28
|
+
abbreviation varchar(50) default null,
|
29
|
+
description varchar(50) default null
|
30
30
|
);
|
31
31
|
|
32
32
|
create sequence products_seq start with 1000;
|
33
33
|
|
34
34
|
create table products (
|
35
35
|
id number(11) primary key,
|
36
|
-
name
|
36
|
+
name varchar(50) default null
|
37
37
|
);
|
38
38
|
|
39
39
|
create table tariffs (
|
@@ -55,7 +55,7 @@ create table product_tariffs (
|
|
55
55
|
create table suburbs (
|
56
56
|
city_id number(11),
|
57
57
|
suburb_id number(11),
|
58
|
-
name
|
58
|
+
name varchar(50) not null,
|
59
59
|
constraint suburbs_pk primary key (city_id, suburb_id)
|
60
60
|
);
|
61
61
|
|
@@ -65,21 +65,21 @@ create table streets (
|
|
65
65
|
id number(11) primary key,
|
66
66
|
city_id number(11) not null,
|
67
67
|
suburb_id number(11) not null,
|
68
|
-
name
|
68
|
+
name varchar(50) not null
|
69
69
|
);
|
70
70
|
|
71
71
|
create sequence users_seq start with 1000;
|
72
72
|
|
73
73
|
create table users (
|
74
74
|
id number(11) primary key,
|
75
|
-
name
|
75
|
+
name varchar(50) not null
|
76
76
|
);
|
77
77
|
|
78
78
|
create sequence articles_seq start with 1000;
|
79
79
|
|
80
80
|
create table articles (
|
81
81
|
id number(11) primary key,
|
82
|
-
name
|
82
|
+
name varchar(50) not null
|
83
83
|
);
|
84
84
|
|
85
85
|
create sequence readings_seq start with 1000;
|
@@ -95,7 +95,7 @@ create sequence groups_seq start with 1000;
|
|
95
95
|
|
96
96
|
create table groups (
|
97
97
|
id number(11) primary key,
|
98
|
-
name
|
98
|
+
name varchar(50) not null
|
99
99
|
);
|
100
100
|
|
101
101
|
create table memberships (
|
@@ -110,7 +110,7 @@ create table membership_statuses (
|
|
110
110
|
id number(11) primary key,
|
111
111
|
user_id number(11) not null,
|
112
112
|
group_id number(11) not null,
|
113
|
-
status
|
113
|
+
status varchar(50) not null
|
114
114
|
);
|
115
115
|
|
116
116
|
create table departments (
|
@@ -124,8 +124,7 @@ create sequence employees_seq start with 1000;
|
|
124
124
|
create table employees (
|
125
125
|
id number(11) not null primary key,
|
126
126
|
department_id number(11) default null,
|
127
|
-
location_id number(11) default null
|
128
|
-
name varchar2(100) default 'anonymous'
|
127
|
+
location_id number(11) default null
|
129
128
|
);
|
130
129
|
|
131
130
|
create sequence salaries_seq start with 1000;
|
@@ -219,8 +218,8 @@ create table seats (
|
|
219
218
|
);
|
220
219
|
|
221
220
|
create table capitols (
|
222
|
-
country
|
223
|
-
city
|
221
|
+
country varchar(100) not null,
|
222
|
+
city varchar(100) not null,
|
224
223
|
primary key (country, city)
|
225
224
|
);
|
226
225
|
|
@@ -235,3 +234,13 @@ create table employees_groups (
|
|
235
234
|
group_id int not null
|
236
235
|
);
|
237
236
|
|
237
|
+
create sequence pk_called_ids_seq start with 1000;
|
238
|
+
|
239
|
+
create table pk_called_ids (
|
240
|
+
id int not null,
|
241
|
+
reference_code int not null,
|
242
|
+
code_label varchar(50) default null,
|
243
|
+
abbreviation varchar(50) default null,
|
244
|
+
description varchar(50) default null,
|
245
|
+
constraint pk_called_ids_pk primary key (id, reference_code)
|
246
|
+
);
|
@@ -41,9 +41,9 @@ create table tariffs (
|
|
41
41
|
tariff_id int not null,
|
42
42
|
start_date date not null,
|
43
43
|
amount int default null,
|
44
|
-
primary key (tariff_id, start_date),
|
45
44
|
created_at timestamp without time zone NOT NULL,
|
46
|
-
updated_at timestamp without time zone NOT NULL
|
45
|
+
updated_at timestamp without time zone NOT NULL,
|
46
|
+
primary key (tariff_id, start_date)
|
47
47
|
);
|
48
48
|
|
49
49
|
create table product_tariffs (
|
@@ -118,7 +118,6 @@ create table employees (
|
|
118
118
|
id serial not null,
|
119
119
|
department_id int default null,
|
120
120
|
location_id int default null,
|
121
|
-
name text not null default 'anonymous',
|
122
121
|
primary key (id)
|
123
122
|
);
|
124
123
|
|