composite_primary_keys 7.0.15 → 7.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +4 -0
- data/lib/composite_primary_keys.rb +5 -0
- data/lib/composite_primary_keys/arel/visitors/to_sql.rb +20 -0
- data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +22 -22
- data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +19 -19
- data/lib/composite_primary_keys/composite_predicates.rb +50 -50
- data/lib/composite_primary_keys/composite_relation.rb +48 -48
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +60 -46
- data/lib/composite_primary_keys/fixtures.rb +22 -22
- data/lib/composite_primary_keys/locking/optimistic.rb +55 -55
- data/lib/composite_primary_keys/relation/query_methods.rb +40 -40
- data/lib/composite_primary_keys/version.rb +1 -1
- data/tasks/databases/oracle.rake +25 -25
- data/test/connections/databases.ci.yml +15 -15
- data/test/connections/native_oracle/connection.rb +11 -11
- data/test/connections/native_oracle_enhanced/connection.rb +16 -16
- data/test/fixtures/comment.rb +7 -7
- data/test/fixtures/db_definitions/db2-create-tables.sql +126 -126
- data/test/fixtures/db_definitions/db2-drop-tables.sql +18 -18
- data/test/fixtures/db_definitions/oracle.drop.sql +45 -45
- data/test/fixtures/db_definitions/oracle.sql +223 -223
- data/test/fixtures/dorm.rb +2 -2
- data/test/fixtures/membership.rb +6 -6
- data/test/fixtures/membership_statuses.yml +16 -16
- data/test/fixtures/memberships.yml +10 -10
- data/test/fixtures/product_tariffs.yml +14 -14
- data/test/fixtures/reference_code.rb +7 -7
- data/test/fixtures/restaurants_suburb.rb +2 -2
- data/test/fixtures/suburb.rb +5 -5
- data/test/fixtures/topic.rb +5 -5
- data/test/fixtures/topic_source.rb +6 -6
- data/test/fixtures/topic_sources.yml +3 -3
- data/test/fixtures/topics.yml +8 -8
- data/test/fixtures/users.yml +10 -10
- data/test/test_attribute_methods.rb +63 -63
- data/test/test_calculations.rb +42 -42
- data/test/test_callbacks.rb +99 -99
- data/test/test_delete_all.rb +5 -0
- data/test/test_dumpable.rb +15 -15
- data/test/test_nested_attributes.rb +124 -124
- data/test/test_optimistic.rb +18 -18
- data/test/test_predicates.rb +40 -40
- data/test/test_santiago.rb +23 -23
- data/test/test_suite.rb +34 -34
- data/test/test_touch.rb +23 -23
- data/test/test_update.rb +71 -71
- metadata +4 -3
@@ -1,22 +1,22 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
class Fixture
|
3
|
-
def find
|
4
|
-
if model_class
|
5
|
-
# CPK
|
6
|
-
# model_class.find(fixture[model_class.primary_key])
|
7
|
-
ids = self.ids(model_class.primary_key)
|
8
|
-
model_class.find(ids)
|
9
|
-
else
|
10
|
-
raise FixtureClassNotFound, "No class attached to find."
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def ids(key)
|
15
|
-
if key.is_a? Array
|
16
|
-
key.map {|a_key| fixture[a_key.to_s] }
|
17
|
-
else
|
18
|
-
fixture[key]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
1
|
+
module ActiveRecord
|
2
|
+
class Fixture
|
3
|
+
def find
|
4
|
+
if model_class
|
5
|
+
# CPK
|
6
|
+
# model_class.find(fixture[model_class.primary_key])
|
7
|
+
ids = self.ids(model_class.primary_key)
|
8
|
+
model_class.find(ids)
|
9
|
+
else
|
10
|
+
raise FixtureClassNotFound, "No class attached to find."
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def ids(key)
|
15
|
+
if key.is_a? Array
|
16
|
+
key.map {|a_key| fixture[a_key.to_s] }
|
17
|
+
else
|
18
|
+
fixture[key]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,55 +1,55 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Locking
|
3
|
-
module Optimistic
|
4
|
-
private
|
5
|
-
def _update_record(attribute_names = @attributes.keys) #:nodoc:
|
6
|
-
return super unless locking_enabled?
|
7
|
-
return 0 if attribute_names.empty?
|
8
|
-
|
9
|
-
lock_col = self.class.locking_column
|
10
|
-
previous_lock_value = send(lock_col).to_i
|
11
|
-
increment_lock
|
12
|
-
|
13
|
-
attribute_names += [lock_col]
|
14
|
-
attribute_names.uniq!
|
15
|
-
|
16
|
-
begin
|
17
|
-
relation = self.class.unscoped
|
18
|
-
|
19
|
-
if self.composite?
|
20
|
-
stmt = relation.where(
|
21
|
-
relation.cpk_id_predicate(relation.table, self.class.primary_key, id_was).and(
|
22
|
-
relation.table[lock_col].eq(self.class.quote_value(previous_lock_value, column_for_attribute(lock_col)))
|
23
|
-
)
|
24
|
-
).arel.compile_update(
|
25
|
-
arel_attributes_with_values_for_update(attribute_names),
|
26
|
-
self.class.primary_key
|
27
|
-
)
|
28
|
-
else
|
29
|
-
stmt = relation.where(
|
30
|
-
relation.table[self.class.primary_key].eq(id).and(
|
31
|
-
relation.table[lock_col].eq(self.class.quote_value(previous_lock_value, column_for_attribute(lock_col)))
|
32
|
-
)
|
33
|
-
).arel.compile_update(
|
34
|
-
arel_attributes_with_values_for_update(attribute_names),
|
35
|
-
self.class.primary_key
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
affected_rows = self.class.connection.update stmt
|
40
|
-
|
41
|
-
unless affected_rows == 1
|
42
|
-
raise ActiveRecord::StaleObjectError.new(self, "update")
|
43
|
-
end
|
44
|
-
|
45
|
-
affected_rows
|
46
|
-
|
47
|
-
# If something went wrong, revert the version.
|
48
|
-
rescue Exception
|
49
|
-
send(lock_col + '=', previous_lock_value)
|
50
|
-
raise
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
1
|
+
module ActiveRecord
|
2
|
+
module Locking
|
3
|
+
module Optimistic
|
4
|
+
private
|
5
|
+
def _update_record(attribute_names = @attributes.keys) #:nodoc:
|
6
|
+
return super unless locking_enabled?
|
7
|
+
return 0 if attribute_names.empty?
|
8
|
+
|
9
|
+
lock_col = self.class.locking_column
|
10
|
+
previous_lock_value = send(lock_col).to_i
|
11
|
+
increment_lock
|
12
|
+
|
13
|
+
attribute_names += [lock_col]
|
14
|
+
attribute_names.uniq!
|
15
|
+
|
16
|
+
begin
|
17
|
+
relation = self.class.unscoped
|
18
|
+
|
19
|
+
if self.composite?
|
20
|
+
stmt = relation.where(
|
21
|
+
relation.cpk_id_predicate(relation.table, self.class.primary_key, id_was).and(
|
22
|
+
relation.table[lock_col].eq(self.class.quote_value(previous_lock_value, column_for_attribute(lock_col)))
|
23
|
+
)
|
24
|
+
).arel.compile_update(
|
25
|
+
arel_attributes_with_values_for_update(attribute_names),
|
26
|
+
self.class.primary_key
|
27
|
+
)
|
28
|
+
else
|
29
|
+
stmt = relation.where(
|
30
|
+
relation.table[self.class.primary_key].eq(id).and(
|
31
|
+
relation.table[lock_col].eq(self.class.quote_value(previous_lock_value, column_for_attribute(lock_col)))
|
32
|
+
)
|
33
|
+
).arel.compile_update(
|
34
|
+
arel_attributes_with_values_for_update(attribute_names),
|
35
|
+
self.class.primary_key
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
affected_rows = self.class.connection.update stmt
|
40
|
+
|
41
|
+
unless affected_rows == 1
|
42
|
+
raise ActiveRecord::StaleObjectError.new(self, "update")
|
43
|
+
end
|
44
|
+
|
45
|
+
affected_rows
|
46
|
+
|
47
|
+
# If something went wrong, revert the version.
|
48
|
+
rescue Exception
|
49
|
+
send(lock_col + '=', previous_lock_value)
|
50
|
+
raise
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,41 +1,41 @@
|
|
1
|
-
module CompositePrimaryKeys::ActiveRecord::QueryMethods
|
2
|
-
|
3
|
-
def reverse_sql_order(order_query)
|
4
|
-
# CPK
|
5
|
-
# order_query = ["#{quoted_table_name}.#{quoted_primary_key} ASC"] if order_query.empty?
|
6
|
-
|
7
|
-
# break apart CPKs
|
8
|
-
order_query = primary_key.map do |key|
|
9
|
-
"#{quoted_table_name}.#{connection.quote_column_name(key)} ASC"
|
10
|
-
end if order_query.empty?
|
11
|
-
|
12
|
-
order_query.map do |o|
|
13
|
-
case o
|
14
|
-
when Arel::Nodes::Ordering
|
15
|
-
o.reverse
|
16
|
-
when String, Symbol
|
17
|
-
o.to_s.split(',').collect do |s|
|
18
|
-
s.strip!
|
19
|
-
s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC')
|
20
|
-
end
|
21
|
-
else
|
22
|
-
o
|
23
|
-
end
|
24
|
-
end.flatten
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
def order(*args)
|
29
|
-
args.map! do |arg|
|
30
|
-
if arg.is_a?(Arel::Nodes::Ordering) && arg.expr.name.is_a?(Array)
|
31
|
-
arg = arg.expr.name.map do |key|
|
32
|
-
cloned_node = arg.clone
|
33
|
-
cloned_node.expr.name = key
|
34
|
-
cloned_node
|
35
|
-
end
|
36
|
-
end
|
37
|
-
arg
|
38
|
-
end if composite?
|
39
|
-
super(*args)
|
40
|
-
end
|
1
|
+
module CompositePrimaryKeys::ActiveRecord::QueryMethods
|
2
|
+
|
3
|
+
def reverse_sql_order(order_query)
|
4
|
+
# CPK
|
5
|
+
# order_query = ["#{quoted_table_name}.#{quoted_primary_key} ASC"] if order_query.empty?
|
6
|
+
|
7
|
+
# break apart CPKs
|
8
|
+
order_query = primary_key.map do |key|
|
9
|
+
"#{quoted_table_name}.#{connection.quote_column_name(key)} ASC"
|
10
|
+
end if order_query.empty?
|
11
|
+
|
12
|
+
order_query.map do |o|
|
13
|
+
case o
|
14
|
+
when Arel::Nodes::Ordering
|
15
|
+
o.reverse
|
16
|
+
when String, Symbol
|
17
|
+
o.to_s.split(',').collect do |s|
|
18
|
+
s.strip!
|
19
|
+
s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC')
|
20
|
+
end
|
21
|
+
else
|
22
|
+
o
|
23
|
+
end
|
24
|
+
end.flatten
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def order(*args)
|
29
|
+
args.map! do |arg|
|
30
|
+
if arg.is_a?(Arel::Nodes::Ordering) && arg.expr.name.is_a?(Array)
|
31
|
+
arg = arg.expr.name.map do |key|
|
32
|
+
cloned_node = arg.clone
|
33
|
+
cloned_node.expr.name = key
|
34
|
+
cloned_node
|
35
|
+
end
|
36
|
+
end
|
37
|
+
arg
|
38
|
+
end if composite?
|
39
|
+
super(*args)
|
40
|
+
end
|
41
41
|
end
|
data/tasks/databases/oracle.rake
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
2
|
-
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
|
3
|
-
|
4
|
-
namespace :oracle do
|
5
|
-
desc 'Build the Oracle test database'
|
6
|
-
task :build_database => :load_connection do
|
7
|
-
options_str = connection_string
|
8
|
-
|
9
|
-
schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'oracle.sql')
|
10
|
-
sh %( sqlplus #{options_str} < #{schema} )
|
11
|
-
end
|
12
|
-
|
13
|
-
desc 'Drop the Oracle test database'
|
14
|
-
task :drop_database => :load_connection do
|
15
|
-
options_str = connection_string
|
16
|
-
sh %( sqlplus #{options_str} < #{File.join(SCHEMA_PATH, 'oracle.drop.sql')} )
|
17
|
-
end
|
18
|
-
|
19
|
-
desc 'Rebuild the Oracle test database'
|
20
|
-
task :rebuild_database => [:drop_database, :build_database]
|
21
|
-
|
22
|
-
task :load_connection do
|
23
|
-
require File.join(PROJECT_ROOT, "test", "connections", "native_oracle", "connection")
|
24
|
-
end
|
25
|
-
end
|
1
|
+
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
2
|
+
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
|
3
|
+
|
4
|
+
namespace :oracle do
|
5
|
+
desc 'Build the Oracle test database'
|
6
|
+
task :build_database => :load_connection do
|
7
|
+
options_str = connection_string
|
8
|
+
|
9
|
+
schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'oracle.sql')
|
10
|
+
sh %( sqlplus #{options_str} < #{schema} )
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Drop the Oracle test database'
|
14
|
+
task :drop_database => :load_connection do
|
15
|
+
options_str = connection_string
|
16
|
+
sh %( sqlplus #{options_str} < #{File.join(SCHEMA_PATH, 'oracle.drop.sql')} )
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Rebuild the Oracle test database'
|
20
|
+
task :rebuild_database => [:drop_database, :build_database]
|
21
|
+
|
22
|
+
task :load_connection do
|
23
|
+
require File.join(PROJECT_ROOT, "test", "connections", "native_oracle", "connection")
|
24
|
+
end
|
25
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
mysql:
|
2
|
-
adapter: mysql2
|
3
|
-
username: travis
|
4
|
-
password: ""
|
5
|
-
database: composite_primary_keys_unittest
|
6
|
-
|
7
|
-
sqlite3:
|
8
|
-
adapter: sqlite3
|
9
|
-
database: db/composite_primary_keys_unittest.sqlite
|
10
|
-
|
11
|
-
postgresql:
|
12
|
-
adapter: postgresql
|
13
|
-
database: composite_primary_keys_unittest
|
14
|
-
username: postgres
|
15
|
-
host: localhost
|
1
|
+
mysql:
|
2
|
+
adapter: mysql2
|
3
|
+
username: travis
|
4
|
+
password: ""
|
5
|
+
database: composite_primary_keys_unittest
|
6
|
+
|
7
|
+
sqlite3:
|
8
|
+
adapter: sqlite3
|
9
|
+
database: db/composite_primary_keys_unittest.sqlite
|
10
|
+
|
11
|
+
postgresql:
|
12
|
+
adapter: postgresql
|
13
|
+
database: composite_primary_keys_unittest
|
14
|
+
username: postgres
|
15
|
+
host: localhost
|
@@ -1,11 +1,11 @@
|
|
1
|
-
print "Using native Oracle\n"
|
2
|
-
|
3
|
-
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
4
|
-
|
5
|
-
def connection_string
|
6
|
-
"#{SPEC['username']}/#{SPEC['password']}@#{SPEC['host']}"
|
7
|
-
end
|
8
|
-
|
9
|
-
# Adapter config setup in locals/database_connections.rb
|
10
|
-
SPEC = CompositePrimaryKeys::ConnectionSpec['oracle']
|
11
|
-
ActiveRecord::Base.establish_connection(SPEC)
|
1
|
+
print "Using native Oracle\n"
|
2
|
+
|
3
|
+
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
4
|
+
|
5
|
+
def connection_string
|
6
|
+
"#{SPEC['username']}/#{SPEC['password']}@#{SPEC['host']}"
|
7
|
+
end
|
8
|
+
|
9
|
+
# Adapter config setup in locals/database_connections.rb
|
10
|
+
SPEC = CompositePrimaryKeys::ConnectionSpec['oracle']
|
11
|
+
ActiveRecord::Base.establish_connection(SPEC)
|
@@ -1,16 +1,16 @@
|
|
1
|
-
print "Using native Oracle Enhanced\n"
|
2
|
-
|
3
|
-
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
4
|
-
|
5
|
-
def connection_string
|
6
|
-
"#{SPEC['username']}/#{SPEC['password']}@#{SPEC['host']}"
|
7
|
-
end
|
8
|
-
|
9
|
-
# Adapter config setup in locals/database_connections.rb
|
10
|
-
SPEC = CompositePrimaryKeys::ConnectionSpec[:oracle]
|
11
|
-
ActiveRecord::Base.establish_connection(SPEC)
|
12
|
-
|
13
|
-
# Change default options for Oracle Enhanced adapter
|
14
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
15
|
-
# Change NLS_DATE_FORMAT to non-default format to verify that all tests should pass
|
16
|
-
ActiveRecord::Base.connection.execute %q{alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS'}
|
1
|
+
print "Using native Oracle Enhanced\n"
|
2
|
+
|
3
|
+
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
4
|
+
|
5
|
+
def connection_string
|
6
|
+
"#{SPEC['username']}/#{SPEC['password']}@#{SPEC['host']}"
|
7
|
+
end
|
8
|
+
|
9
|
+
# Adapter config setup in locals/database_connections.rb
|
10
|
+
SPEC = CompositePrimaryKeys::ConnectionSpec[:oracle]
|
11
|
+
ActiveRecord::Base.establish_connection(SPEC)
|
12
|
+
|
13
|
+
# Change default options for Oracle Enhanced adapter
|
14
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
15
|
+
# Change NLS_DATE_FORMAT to non-default format to verify that all tests should pass
|
16
|
+
ActiveRecord::Base.connection.execute %q{alter session set nls_date_format = 'DD-MON-YYYY HH24:MI:SS'}
|
data/test/fixtures/comment.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
class Comment < ActiveRecord::Base
|
2
|
-
belongs_to :person, :polymorphic => true
|
3
|
-
belongs_to :hack
|
4
|
-
|
5
|
-
enum :shown => [ :true, :false ]
|
6
|
-
end
|
7
|
-
|
1
|
+
class Comment < ActiveRecord::Base
|
2
|
+
belongs_to :person, :polymorphic => true
|
3
|
+
belongs_to :hack
|
4
|
+
|
5
|
+
enum :shown => [ :true, :false ]
|
6
|
+
end
|
7
|
+
|
@@ -1,126 +1,126 @@
|
|
1
|
-
CREATE TABLE topics (
|
2
|
-
id integer NOT NULL,
|
3
|
-
name varchar(50) default NULL,
|
4
|
-
feed_size integer default NULL,
|
5
|
-
PRIMARY KEY (id)
|
6
|
-
);
|
7
|
-
|
8
|
-
CREATE TABLE topic_sources (
|
9
|
-
topic_id integer NOT NULL,
|
10
|
-
platform varchar(50) NOT NULL,
|
11
|
-
keywords varchar(50) default NULL,
|
12
|
-
PRIMARY KEY (topic_id,platform)
|
13
|
-
);
|
14
|
-
|
15
|
-
CREATE TABLE reference_types (
|
16
|
-
reference_type_id integer NOT NULL generated by default as identity (start with 100, increment by 1, no cache),
|
17
|
-
type_label varchar(50) default NULL,
|
18
|
-
abbreviation varchar(50) default NULL,
|
19
|
-
description varchar(50) default NULL,
|
20
|
-
PRIMARY KEY (reference_type_id)
|
21
|
-
);
|
22
|
-
|
23
|
-
CREATE TABLE reference_codes (
|
24
|
-
reference_type_id integer,
|
25
|
-
reference_code integer NOT NULL,
|
26
|
-
code_label varchar(50) default NULL,
|
27
|
-
abbreviation varchar(50) default NULL,
|
28
|
-
description varchar(50) default NULL,
|
29
|
-
PRIMARY KEY (reference_type_id,reference_code)
|
30
|
-
);
|
31
|
-
|
32
|
-
CREATE TABLE products (
|
33
|
-
id integer NOT NULL,
|
34
|
-
name varchar(50) default NULL,
|
35
|
-
PRIMARY KEY (id)
|
36
|
-
);
|
37
|
-
|
38
|
-
CREATE TABLE tariffs (
|
39
|
-
tariff_id integer NOT NULL,
|
40
|
-
start_date date NOT NULL,
|
41
|
-
amount integer default NULL,
|
42
|
-
PRIMARY KEY (tariff_id,start_date)
|
43
|
-
);
|
44
|
-
|
45
|
-
CREATE TABLE product_tariffs (
|
46
|
-
product_id integer NOT NULL,
|
47
|
-
tariff_id integer NOT NULL,
|
48
|
-
tariff_start_date date NOT NULL,
|
49
|
-
PRIMARY KEY (product_id,tariff_id,tariff_start_date)
|
50
|
-
);
|
51
|
-
|
52
|
-
CREATE TABLE suburbs (
|
53
|
-
city_id integer NOT NULL,
|
54
|
-
suburb_id integer NOT NULL,
|
55
|
-
name varchar(50) NOT NULL,
|
56
|
-
PRIMARY KEY (city_id,suburb_id)
|
57
|
-
);
|
58
|
-
|
59
|
-
CREATE TABLE streets (
|
60
|
-
id integer NOT NULL ,
|
61
|
-
city_id integer NOT NULL,
|
62
|
-
suburb_id integer NOT NULL,
|
63
|
-
name varchar(50) NOT NULL,
|
64
|
-
PRIMARY KEY (id)
|
65
|
-
);
|
66
|
-
|
67
|
-
CREATE TABLE users (
|
68
|
-
id integer NOT NULL ,
|
69
|
-
name varchar(50) NOT NULL,
|
70
|
-
PRIMARY KEY (id)
|
71
|
-
);
|
72
|
-
|
73
|
-
CREATE TABLE articles (
|
74
|
-
id integer NOT NULL ,
|
75
|
-
name varchar(50) NOT NULL,
|
76
|
-
PRIMARY KEY (id)
|
77
|
-
);
|
78
|
-
|
79
|
-
CREATE TABLE readings (
|
80
|
-
id integer NOT NULL ,
|
81
|
-
user_id integer NOT NULL,
|
82
|
-
article_id integer NOT NULL,
|
83
|
-
rating integer NOT NULL,
|
84
|
-
PRIMARY KEY (id)
|
85
|
-
);
|
86
|
-
|
87
|
-
CREATE TABLE groups (
|
88
|
-
id integer NOT NULL ,
|
89
|
-
name varchar(50) NOT NULL,
|
90
|
-
PRIMARY KEY (id)
|
91
|
-
);
|
92
|
-
|
93
|
-
CREATE TABLE memberships (
|
94
|
-
user_id integer NOT NULL,
|
95
|
-
group_id integer NOT NULL,
|
96
|
-
PRIMARY KEY (user_id,group_id)
|
97
|
-
);
|
98
|
-
|
99
|
-
CREATE TABLE membership_statuses (
|
100
|
-
id integer NOT NULL ,
|
101
|
-
user_id integer NOT NULL,
|
102
|
-
group_id integer NOT NULL,
|
103
|
-
status varchar(50) NOT NULL,
|
104
|
-
PRIMARY KEY (id)
|
105
|
-
);
|
106
|
-
|
107
|
-
create table restaurants (
|
108
|
-
franchise_id integer not null,
|
109
|
-
store_id integer not null,
|
110
|
-
name varchar(100),
|
111
|
-
lock_version integer default 0,
|
112
|
-
primary key (franchise_id, store_id)
|
113
|
-
);
|
114
|
-
|
115
|
-
create table restaurants_suburbs (
|
116
|
-
franchise_id integer not null,
|
117
|
-
store_id integer not null,
|
118
|
-
city_id integer not null,
|
119
|
-
suburb_id integer not null
|
120
|
-
);
|
121
|
-
|
122
|
-
create table products_restaurants (
|
123
|
-
product_id integer not null,
|
124
|
-
franchise_id integer not null,
|
125
|
-
store_id integer not null
|
126
|
-
);
|
1
|
+
CREATE TABLE topics (
|
2
|
+
id integer NOT NULL,
|
3
|
+
name varchar(50) default NULL,
|
4
|
+
feed_size integer default NULL,
|
5
|
+
PRIMARY KEY (id)
|
6
|
+
);
|
7
|
+
|
8
|
+
CREATE TABLE topic_sources (
|
9
|
+
topic_id integer NOT NULL,
|
10
|
+
platform varchar(50) NOT NULL,
|
11
|
+
keywords varchar(50) default NULL,
|
12
|
+
PRIMARY KEY (topic_id,platform)
|
13
|
+
);
|
14
|
+
|
15
|
+
CREATE TABLE reference_types (
|
16
|
+
reference_type_id integer NOT NULL generated by default as identity (start with 100, increment by 1, no cache),
|
17
|
+
type_label varchar(50) default NULL,
|
18
|
+
abbreviation varchar(50) default NULL,
|
19
|
+
description varchar(50) default NULL,
|
20
|
+
PRIMARY KEY (reference_type_id)
|
21
|
+
);
|
22
|
+
|
23
|
+
CREATE TABLE reference_codes (
|
24
|
+
reference_type_id integer,
|
25
|
+
reference_code integer NOT NULL,
|
26
|
+
code_label varchar(50) default NULL,
|
27
|
+
abbreviation varchar(50) default NULL,
|
28
|
+
description varchar(50) default NULL,
|
29
|
+
PRIMARY KEY (reference_type_id,reference_code)
|
30
|
+
);
|
31
|
+
|
32
|
+
CREATE TABLE products (
|
33
|
+
id integer NOT NULL,
|
34
|
+
name varchar(50) default NULL,
|
35
|
+
PRIMARY KEY (id)
|
36
|
+
);
|
37
|
+
|
38
|
+
CREATE TABLE tariffs (
|
39
|
+
tariff_id integer NOT NULL,
|
40
|
+
start_date date NOT NULL,
|
41
|
+
amount integer default NULL,
|
42
|
+
PRIMARY KEY (tariff_id,start_date)
|
43
|
+
);
|
44
|
+
|
45
|
+
CREATE TABLE product_tariffs (
|
46
|
+
product_id integer NOT NULL,
|
47
|
+
tariff_id integer NOT NULL,
|
48
|
+
tariff_start_date date NOT NULL,
|
49
|
+
PRIMARY KEY (product_id,tariff_id,tariff_start_date)
|
50
|
+
);
|
51
|
+
|
52
|
+
CREATE TABLE suburbs (
|
53
|
+
city_id integer NOT NULL,
|
54
|
+
suburb_id integer NOT NULL,
|
55
|
+
name varchar(50) NOT NULL,
|
56
|
+
PRIMARY KEY (city_id,suburb_id)
|
57
|
+
);
|
58
|
+
|
59
|
+
CREATE TABLE streets (
|
60
|
+
id integer NOT NULL ,
|
61
|
+
city_id integer NOT NULL,
|
62
|
+
suburb_id integer NOT NULL,
|
63
|
+
name varchar(50) NOT NULL,
|
64
|
+
PRIMARY KEY (id)
|
65
|
+
);
|
66
|
+
|
67
|
+
CREATE TABLE users (
|
68
|
+
id integer NOT NULL ,
|
69
|
+
name varchar(50) NOT NULL,
|
70
|
+
PRIMARY KEY (id)
|
71
|
+
);
|
72
|
+
|
73
|
+
CREATE TABLE articles (
|
74
|
+
id integer NOT NULL ,
|
75
|
+
name varchar(50) NOT NULL,
|
76
|
+
PRIMARY KEY (id)
|
77
|
+
);
|
78
|
+
|
79
|
+
CREATE TABLE readings (
|
80
|
+
id integer NOT NULL ,
|
81
|
+
user_id integer NOT NULL,
|
82
|
+
article_id integer NOT NULL,
|
83
|
+
rating integer NOT NULL,
|
84
|
+
PRIMARY KEY (id)
|
85
|
+
);
|
86
|
+
|
87
|
+
CREATE TABLE groups (
|
88
|
+
id integer NOT NULL ,
|
89
|
+
name varchar(50) NOT NULL,
|
90
|
+
PRIMARY KEY (id)
|
91
|
+
);
|
92
|
+
|
93
|
+
CREATE TABLE memberships (
|
94
|
+
user_id integer NOT NULL,
|
95
|
+
group_id integer NOT NULL,
|
96
|
+
PRIMARY KEY (user_id,group_id)
|
97
|
+
);
|
98
|
+
|
99
|
+
CREATE TABLE membership_statuses (
|
100
|
+
id integer NOT NULL ,
|
101
|
+
user_id integer NOT NULL,
|
102
|
+
group_id integer NOT NULL,
|
103
|
+
status varchar(50) NOT NULL,
|
104
|
+
PRIMARY KEY (id)
|
105
|
+
);
|
106
|
+
|
107
|
+
create table restaurants (
|
108
|
+
franchise_id integer not null,
|
109
|
+
store_id integer not null,
|
110
|
+
name varchar(100),
|
111
|
+
lock_version integer default 0,
|
112
|
+
primary key (franchise_id, store_id)
|
113
|
+
);
|
114
|
+
|
115
|
+
create table restaurants_suburbs (
|
116
|
+
franchise_id integer not null,
|
117
|
+
store_id integer not null,
|
118
|
+
city_id integer not null,
|
119
|
+
suburb_id integer not null
|
120
|
+
);
|
121
|
+
|
122
|
+
create table products_restaurants (
|
123
|
+
product_id integer not null,
|
124
|
+
franchise_id integer not null,
|
125
|
+
store_id integer not null
|
126
|
+
);
|