activefacts-compositions 1.9.17 → 1.9.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/activefacts-compositions.gemspec +2 -2
  3. data/lib/activefacts/compositions/binary.rb +1 -1
  4. data/lib/activefacts/compositions/compositor.rb +16 -12
  5. data/lib/activefacts/compositions/datavault.rb +110 -115
  6. data/lib/activefacts/compositions/relational.rb +137 -94
  7. data/lib/activefacts/compositions/staging.rb +89 -27
  8. data/lib/activefacts/compositions/traits/datavault.rb +116 -49
  9. data/lib/activefacts/compositions/traits/rails.rb +2 -2
  10. data/lib/activefacts/compositions/version.rb +1 -1
  11. data/lib/activefacts/generator/doc/cwm.rb +6 -18
  12. data/lib/activefacts/generator/doc/ldm.rb +1 -1
  13. data/lib/activefacts/generator/etl/unidex.rb +341 -0
  14. data/lib/activefacts/generator/oo.rb +31 -14
  15. data/lib/activefacts/generator/rails/models.rb +6 -5
  16. data/lib/activefacts/generator/rails/schema.rb +5 -9
  17. data/lib/activefacts/generator/ruby.rb +2 -2
  18. data/lib/activefacts/generator/sql/mysql.rb +3 -184
  19. data/lib/activefacts/generator/sql/oracle.rb +3 -152
  20. data/lib/activefacts/generator/sql/postgres.rb +3 -145
  21. data/lib/activefacts/generator/sql/server.rb +3 -126
  22. data/lib/activefacts/generator/sql.rb +54 -422
  23. data/lib/activefacts/generator/summary.rb +15 -6
  24. data/lib/activefacts/generator/traits/expr.rb +41 -0
  25. data/lib/activefacts/generator/traits/sql/mysql.rb +280 -0
  26. data/lib/activefacts/generator/traits/sql/oracle.rb +265 -0
  27. data/lib/activefacts/generator/traits/sql/postgres.rb +287 -0
  28. data/lib/activefacts/generator/traits/sql/server.rb +262 -0
  29. data/lib/activefacts/generator/traits/sql.rb +538 -0
  30. metadata +13 -8
  31. data/lib/activefacts/compositions/docgraph.rb +0 -798
  32. data/lib/activefacts/compositions/staging/persistent.rb +0 -107
@@ -3,13 +3,11 @@
3
3
  #
4
4
  # Copyright (c) 2009-2016 Clifford Heath. Read the LICENSE file.
5
5
  #
6
- # Reserved words gathered from:
7
- # https://dev.mysql.com/doc/refman/5.7/en/keywords.html
8
- #
9
6
  require 'digest/sha1'
10
7
  require 'activefacts/metamodel'
11
8
  require 'activefacts/compositions'
12
9
  require 'activefacts/generator/sql'
10
+ require 'activefacts/generator/traits/sql/mysql'
13
11
 
14
12
  module ActiveFacts
15
13
  module Generators
@@ -17,187 +15,8 @@ module ActiveFacts
17
15
  # * underscore
18
16
  class SQL
19
17
  class MySQL < SQL
20
- def self.options
21
- super.merge({
22
- # no: [String, "no new options defined here"]
23
- })
24
- end
25
-
26
- def table_name_max
27
- 64
28
- end
29
-
30
- def data_type_context
31
- MySQLDataTypeContext.new
32
- end
33
-
34
- def auto_assign_modifier
35
- ' AUTO_INCREMENT'
36
- end
37
-
38
- def generate_schema
39
- ''
40
- end
41
-
42
- def normalise_type(type_name, length, value_constraint, options)
43
- type = MM::DataType.normalise(type_name)
44
- case type
45
- when MM::DataType::TYPE_Integer
46
- if aa = options[:auto_assign]
47
- 'BIGINT'
48
- else
49
- super
50
- end
51
- when MM::DataType::TYPE_Money; ['DECIMAL', length]
52
- when MM::DataType::TYPE_DateTime; 'DATETIME'
53
- when MM::DataType::TYPE_Timestamp;'DATETIME'
54
- when MM::DataType::TYPE_Binary;
55
- if type_name =~ /^(guid|uuid)$/i && (!length || length == 16)
56
- if ![nil, ''].include?(options[:auto_assign])
57
- options[:default] = " DEFAULT UNHEX(REPLACE(UUID(),'-',''))"
58
- options.delete(:auto_assign) # Don't auto-assign foreign keys
59
- end
60
- return ['BINARY', 16]
61
- end
62
-
63
- super type_name, length, value_constraint, options
64
- # MySQL has various non-standard blob types also
65
- else
66
- super
67
- end
68
- end
69
-
70
- # Reserved words cannot be used anywhere without quoting.
71
- # Keywords have existing definitions, so should not be used without quoting.
72
- # Both lists here are added to the supertype's lists
73
- def reserved_words
74
- @mysql_reserved_words ||= %w{
75
- ACCESSIBLE ANALYZE CHANGE DATABASE DATABASES DAY_HOUR
76
- DAY_MICROSECOND DAY_MINUTE DAY_SECOND DELAYED DISTINCTROW
77
- DIV DUAL ENCLOSED ESCAPED EXPLAIN FLOAT4 FLOAT8 FORCE
78
- FULLTEXT HIGH_PRIORITY HOUR_MICROSECOND HOUR_MINUTE
79
- HOUR_SECOND INDEX INFILE INT1 INT2 INT3 INT4 INT8
80
- IO_AFTER_GTIDS IO_BEFORE_GTIDS KEYS KILL LINEAR LINES
81
- LOAD LOCK LONG LONGBLOB LONGTEXT LOW_PRIORITY MASTER_BIND
82
- MASTER_SSL_VERIFY_SERVER_CERT MEDIUMBLOB MEDIUMINT
83
- MEDIUMTEXT MIDDLEINT MINUTE_MICROSECOND MINUTE_SECOND
84
- NO_WRITE_TO_BINLOG OPTIMIZE OPTIMIZER_COSTS OPTIONALLY
85
- OUTFILE PURGE READ_WRITE REGEXP RENAME REPLACE REQUIRE
86
- RLIKE SCHEMAS SECOND_MICROSECOND SEPARATOR SHOW SPATIAL
87
- SQL_BIG_RESULT SQL_CALC_FOUND_ROWS SQL_SMALL_RESULT SSL
88
- STARTING STORED STRAIGHT_JOIN TERMINATED TINYBLOB TINYINT
89
- TINYTEXT UNLOCK UNSIGNED USE UTC_DATE UTC_TIME UTC_TIMESTAMP
90
- VARCHARACTER VIRTUAL XOR YEAR_MONTH ZEROFILL _FILENAME
91
- }
92
- super + @mysql_reserved_words
93
- end
94
-
95
- def key_words
96
- # These keywords should not be used for columns or tables:
97
- @mysql_key_words ||= %w{
98
- ACCOUNT AGAINST AGGREGATE ALGORITHM ANALYSE ASCII
99
- AUTOEXTEND_SIZE AUTO_INCREMENT AVG_ROW_LENGTH BACKUP
100
- BINLOG BLOCK BOOL BTREE BYTE CACHE CHANGED CHANNEL
101
- CHARSET CHECKSUM CIPHER CLIENT CODE COLUMN_FORMAT COMMENT
102
- COMPACT COMPLETION COMPRESSED COMPRESSION CONCURRENT
103
- CONSISTENT CONTEXT CPU DATAFILE DATETIME DEFAULT_AUTH
104
- DELAY_KEY_WRITE DES_KEY_FILE DIRECTORY DISABLE DISCARD
105
- DISK DUMPFILE DUPLICATE ENABLE ENCRYPTION ENDS ENGINE
106
- ENGINES ENUM ERROR ERRORS EVENT EVENTS EXCHANGE EXPANSION
107
- EXPIRE EXPORT EXTENDED EXTENT_SIZE FAST FAULTS FIELDS
108
- FILE_BLOCK_SIZE FIXED FLUSH FOLLOWS FORMAT GEOMETRY
109
- GEOMETRYCOLLECTION GET_FORMAT GRANTS GROUP_REPLICATION
110
- HASH HELP HOST HOSTS IDENTIFIED IGNORE_SERVER_IDS INDEXES
111
- INITIAL_SIZE INSERT_METHOD INSTALL IO IO_THREAD IPC
112
- ISSUER JSON KEY_BLOCK_SIZE LEAVES LESS LINESTRING LIST
113
- LOCKS LOGFILE LOGS MASTER MASTER_AUTO_POSITION
114
- MASTER_CONNECT_RETRY MASTER_DELAY MASTER_HEARTBEAT_PERIOD
115
- MASTER_HOST MASTER_LOG_FILE MASTER_LOG_POS MASTER_PASSWORD
116
- MASTER_PORT MASTER_RETRY_COUNT MASTER_SERVER_ID MASTER_SSL
117
- MASTER_SSL_CA MASTER_SSL_CAPATH MASTER_SSL_CERT
118
- MASTER_SSL_CIPHER MASTER_SSL_CRL MASTER_SSL_CRLPATH
119
- MASTER_SSL_KEY MASTER_TLS_VERSION MASTER_USER
120
- MAX_CONNECTIONS_PER_HOUR MAX_QUERIES_PER_HOUR MAX_ROWS
121
- MAX_SIZE MAX_STATEMENT_TIME MAX_UPDATES_PER_HOUR
122
- MAX_USER_CONNECTIONS MEDIUM MEMORY MICROSECOND MIGRATE
123
- MIN_ROWS MODE MODIFY MULTILINESTRING MULTIPOINT
124
- MULTIPOLYGON MUTEX MYSQL_ERRNO NDB NDBCLUSTER NEVER
125
- NODEGROUP NONBLOCKING NO_WAIT NVARCHAR OLD_PASSWORD ONE
126
- OWNER PACK_KEYS PAGE PARSER PARSE_GCOL_EXPR PARTITIONING
127
- PARTITIONS PASSWORD PHASE PLUGIN PLUGINS PLUGIN_DIR
128
- POINT POLYGON PORT PREV PROCESSLIST PROFILE PROFILES
129
- PROXY QUARTER QUERY QUICK READ_ONLY REBUILD RECOVER
130
- REDOFILE REDO_BUFFER_SIZE REDUNDANT RELAY RELAYLOG
131
- RELAY_LOG_FILE RELAY_LOG_POS RELAY_THREAD RELOAD REMOVE
132
- REORGANIZE REPAIR REPLICATE_DO_DB REPLICATE_DO_TABLE
133
- REPLICATE_IGNORE_DB REPLICATE_IGNORE_TABLE REPLICATE_REWRITE_DB
134
- REPLICATE_WILD_DO_TABLE REPLICATE_WILD_IGNORE_TABLE
135
- REPLICATION RESET RESUME REVERSE ROTATE ROW_FORMAT RTREE
136
- SCHEDULE SERIAL SHARE SHUTDOWN SIGNED SLAVE SLOW SNAPSHOT
137
- SOCKET SONAME SOUNDS SQL_AFTER_GTIDS SQL_AFTER_MTS_GAPS
138
- SQL_BEFORE_GTIDS SQL_BUFFER_RESULT SQL_CACHE SQL_NO_CACHE
139
- SQL_THREAD SQL_TSI_DAY SQL_TSI_HOUR SQL_TSI_MINUTE
140
- SQL_TSI_MONTH SQL_TSI_QUARTER SQL_TSI_SECOND SQL_TSI_WEEK
141
- SQL_TSI_YEAR STACKED STARTS STATS_AUTO_RECALC
142
- STATS_PERSISTENT STATS_SAMPLE_PAGES STATUS STOP STORAGE
143
- STRING SUBJECT SUBPARTITION SUBPARTITIONS SUPER SUSPEND
144
- SWAPS SWITCHES TABLES TABLESPACE TABLE_CHECKSUM TEMPTABLE
145
- TEXT THAN TIMESTAMPADD TIMESTAMPDIFF TRIGGERS TYPES
146
- UNDEFINED UNDOFILE UNDO_BUFFER_SIZE UNICODE UNINSTALL
147
- UPGRADE USER_RESOURCES USE_FRM VALIDATION VARIABLES
148
- WAIT WARNINGS WEEK WEIGHT_STRING X509 XA XID
149
- }
150
-
151
- super + @mysql_key_words
152
- end
153
-
154
- def go s = ''
155
- "#{s};\n\n"
156
- end
157
-
158
- def open_escape
159
- '`'
160
- end
161
-
162
- def close_escape
163
- '`'
164
- end
165
-
166
- def index_kind(index)
167
- ''
168
- end
169
-
170
- class MySQLDataTypeContext < SQLDataTypeContext
171
- def integer_ranges
172
- [
173
- ['TINYINT', -2**7, 2**7-1],
174
- ['TINYINT UNSIGNED', 0, 2**8-1],
175
- ['MEDIUMINT', -2**23, 2**23-1],
176
- ] + super
177
- end
178
-
179
- def boolean_type
180
- 'BOOLEAN'
181
- end
182
-
183
- def valid_from_type
184
- 'DATETIME' # The TIMESTAMP type starts in 1970
185
- end
186
-
187
- def default_char_type
188
- (@unicode ? 'N' : '') +
189
- 'CHAR'
190
- end
191
-
192
- def default_varchar_type
193
- (@unicode ? 'N' : '') +
194
- 'VARCHAR'
195
- end
196
-
197
- def date_time_type
198
- 'DATETIME'
199
- end
200
- end
18
+ prepend Traits::SQL::MySQL
19
+ extend Traits::SQL::MySQL # Needed for class methods, like options
201
20
  end
202
21
 
203
22
  end
@@ -3,13 +3,11 @@
3
3
  #
4
4
  # Copyright (c) 2009-2016 Clifford Heath. Read the LICENSE file.
5
5
  #
6
- # Reserved words gathered from:
7
- # https://docs.oracle.com/cd/B28359_01/appdev.111/b31231/appb.htm
8
- #
9
6
  require 'digest/sha1'
10
7
  require 'activefacts/metamodel'
11
8
  require 'activefacts/compositions'
12
9
  require 'activefacts/generator/sql'
10
+ require 'activefacts/generator/traits/sql/oracle'
13
11
 
14
12
  module ActiveFacts
15
13
  module Generators
@@ -17,155 +15,8 @@ module ActiveFacts
17
15
  # * underscore
18
16
  class SQL
19
17
  class Oracle < SQL
20
- def self.options
21
- super.merge({
22
- # no: [String, "no new options defined here"]
23
- })
24
- end
25
-
26
- def initialize composition, options = {}
27
- super(composition, {'tables' => 'shout', 'columns' => 'shout'}.merge(options))
28
- end
29
-
30
- def table_name_max
31
- 30
32
- end
33
-
34
- def data_type_context
35
- OracleDataTypeContext.new
36
- end
37
-
38
- def auto_assign_modifier
39
- ' GENERATED BY DEFAULT ON NULL AS IDENTITY'
40
- end
41
-
42
- def generate_schema
43
- ''
44
- end
45
-
46
- def normalise_type(type_name, length, value_constraint, options)
47
- type = MM::DataType.normalise(type_name)
48
- case type
49
- when MM::DataType::TYPE_Integer
50
- if aa = options[:auto_assign]
51
- 'LONGINTEGER'
52
- else
53
- super
54
- end
55
- when MM::DataType::TYPE_Money; 'MONEY'
56
- when MM::DataType::TYPE_DateTime; 'DATETIME'
57
- when MM::DataType::TYPE_Timestamp;'DATETIME'
58
- when MM::DataType::TYPE_Binary;
59
- if type_name =~ /^(guid|uuid)$/i && (!length || length == 16)
60
- if ![nil, ''].include?(options[:auto_assign])
61
- options[:default] = " DEFAULT SYS_GUID()"
62
- options.delete(:auto_assign)
63
- end
64
- return ['RAW', 32]
65
- end
66
- ['LOB', length]
67
- else
68
- super
69
- end
70
- end
71
-
72
- # Reserved words cannot be used anywhere without quoting.
73
- # Keywords have existing definitions, so should not be used without quoting.
74
- # Both lists here are added to the supertype's lists
75
- def reserved_words
76
- @oracle_reserved_words ||= %w{
77
- ACCESS ARRAYLEN AUDIT CLUSTER COMMENT COMPRESS EXCLUSIVE
78
- IDENTIFIED INDEX INITIAL LOCK LONG MAXEXTENTS MINUS
79
- MODE MODIFY NOAUDIT NOCOMPRESS NOTFOUND NOWAIT OFFLINE
80
- ONLINE PCTFREE RAW RENAME RESOURCE ROWID ROWLABEL ROWNUM
81
- SHARE SQLBUF SUCCESSFUL SYNONYM SYSDATE UID VALIDATE
82
- VARCHAR2
83
- }
84
- @oracle_plsql_reserved_words ||= %w{
85
- ABORT ACCEPT ACCESS ARRAYLEN ASSERT ASSIGN BASE_TABLE
86
- BINARY_INTEGER BODY CHAR_BASE CLUSTER CLUSTERS COLAUTH
87
- COMPRESS CONSTANT CRASH CURRVAL DATABASE DATA_BASE DBA
88
- DEBUGOFF DEBUGON DEFINITION DELAY DELTA DIGITS DISPOSE
89
- ELSIF ENTRY EXCEPTION_INIT FORM GENERIC IDENTIFIED INDEX
90
- INDEXES LIMITED MINUS MLSLABEL MODE NEXTVAL NOCOMPRESS
91
- NUMBER_BASE PACKAGE PCTFREE POSITIVE PRAGMA PRIVATE
92
- RAISE RECORD REMR RENAME RESOURCE REVERSE ROWID ROWLABEL
93
- ROWNUM ROWTYPE RUN SEPARATE SQLERRM STDDEV SUBTYPE
94
- TABAUTH TABLES TASK TERMINATE USE VARCHAR2 VARIANCE
95
- VIEWS XOR
96
- }
97
- super + @oracle_reserved_words
98
- end
99
-
100
- def key_words
101
- # These keywords should not be used for columns or tables:
102
- @oracle_key_words ||= %w{
103
- ANALYZE ARCHIVE ARCHIVELOG BACKUP BECOME BLOCK BODY
104
- CACHE CANCEL CHANGE CHECKPOINT COMPILE CONTENTS CONTROLFILE
105
- DATABASE DATAFILE DBA DISABLE DISMOUNT DUMP ENABLE
106
- EVENTS EXCEPTIONS EXPLAIN EXTENT EXTERNALLY FLUSH FORCE
107
- FREELIST FREELISTS INITRANS LAYER LISTS LOGFILE MANAGE
108
- MANUAL MAXDATAFILES MAXINSTANCES MAXLOGFILES MAXLOGHISTORY
109
- MAXLOGMEMBERS MAXTRANS MINEXTENTS MOUNT NOARCHIVELOG
110
- NOCACHE NOCYCLE NOMAXVALUE NOMINVALUE NOORDER NORESETLOGS
111
- NORMAL NOSORT OPTIMAL OWN PACKAGE PARALLEL PCTINCREASE
112
- PCTUSED PLAN PRIVATE PROFILE QUOTA RECOVER RESETLOGS
113
- RESTRICTED REUSE ROLES SCN SEGMENT SHARED SNAPSHOT SORT
114
- STATEMENT_ID STATISTICS STOP STORAGE SWITCH TABLES
115
- TABLESPACE THREAD TRACING TRIGGERS UNLIMITED USE
116
- }
117
- super + @oracle_key_words
118
- end
119
-
120
- def go s = ''
121
- "#{s};\n\n"
122
- end
123
-
124
- def open_escape
125
- '"'
126
- end
127
-
128
- def close_escape
129
- '"'
130
- end
131
-
132
- def index_kind(index)
133
- ''
134
- end
135
-
136
- class OracleDataTypeContext < SQLDataTypeContext
137
- def integer_ranges
138
- [
139
- ['SHORTINTEGER', -2**15, 2**15-1], # The standard says -10^5..10^5 (less than 16 bits)
140
- ['INTEGER', -2**31, 2**31-1], # The standard says -10^10..10^10 (more than 32 bits!)
141
- ['LONGINTEGER', -2**63, 2**63-1], # The standard says -10^19..10^19 (less than 64 bits)
142
- ]
143
- end
144
-
145
- def boolean_type
146
- 'BOOLEAN'
147
- end
148
-
149
- def valid_from_type
150
- 'TIMESTAMP'
151
- end
152
-
153
- # There is no performance benefit in using fixed-length CHAR fields,
154
- # and an added burden of trimming the implicitly added white-space
155
- def default_char_type
156
- (@unicode ? 'N' : '') +
157
- 'VARCHAR'
158
- end
159
-
160
- def default_varchar_type
161
- (@unicode ? 'N' : '') +
162
- 'VARCHAR'
163
- end
164
-
165
- def date_time_type
166
- 'TIMESTAMP'
167
- end
168
- end
18
+ prepend Traits::SQL::Oracle
19
+ extend Traits::SQL::Oracle # Needed for class methods, like options
169
20
  end
170
21
 
171
22
  end
@@ -3,13 +3,11 @@
3
3
  #
4
4
  # Copyright (c) 2017 Clifford Heath. Read the LICENSE file.
5
5
  #
6
- # Reserved words gathered from:
7
- # https://www.postgresql.org/docs/9.5/static/sql-keywords-appendix.html
8
- #
9
6
  require 'digest/sha1'
10
7
  require 'activefacts/metamodel'
11
8
  require 'activefacts/compositions'
12
9
  require 'activefacts/generator/sql'
10
+ require 'activefacts/generator/traits/sql/postgres'
13
11
 
14
12
  module ActiveFacts
15
13
  module Generators
@@ -17,148 +15,8 @@ module ActiveFacts
17
15
  # * underscore
18
16
  class SQL
19
17
  class Postgres < SQL
20
- def self.options
21
- super.merge({
22
- # no: [String, "no new options defined here"]
23
- })
24
- end
25
-
26
- def initialize composition, options = {}
27
- super(composition, {'tables' => 'snake', 'columns' => 'snake'}.merge(options))
28
- end
29
-
30
- def table_name_max
31
- 63
32
- end
33
-
34
- def data_type_context
35
- PostgresDataTypeContext.new
36
- end
37
-
38
- def auto_assign_modifier
39
- ''
40
- end
41
-
42
- def generate_schema
43
- go "CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public"
44
- end
45
-
46
- def normalise_type(type_name, length, value_constraint, options)
47
- if type_name =~ /^(guid|uuid)$/i
48
- if ![nil, ''].include?(options[:auto_assign])
49
- options[:default] = " DEFAULT 'gen_random_uuid()'"
50
- end
51
- return ['UUID']
52
- end
53
-
54
- type = MM::DataType.normalise(type_name)
55
- case type
56
- when MM::DataType::TYPE_Integer
57
- if aa = options[:auto_assign]
58
- if aa.size > 0
59
- 'BIGSERIAL'
60
- else
61
- 'BIGINT'
62
- end
63
- else
64
- super
65
- end
66
- when MM::DataType::TYPE_Money; 'MONEY'
67
- when MM::DataType::TYPE_DateTime; 'TIMESTAMP'
68
- when MM::DataType::TYPE_Timestamp;'TIMESTAMP'
69
- when MM::DataType::TYPE_Binary;
70
- if length && length <= 8192
71
- super
72
- else
73
- 'IMAGE'
74
- end
75
- else
76
- super
77
- end
78
- end
79
-
80
- # Reserved words cannot be used anywhere without quoting.
81
- # Keywords have existing definitions, so should not be used without quoting.
82
- # Both lists here are added to the supertype's lists
83
- def reserved_words
84
- @postgres_reserved_words ||= %w{
85
- ANALYSE ANALYZE LIMIT PLACING RETURNING VARIADIC
86
- }
87
- super + @postgres_reserved_words
88
- end
89
-
90
- def key_words
91
- # These keywords should not be used for columns or tables:
92
- @postgres_key_words ||= %w{
93
- ABORT ACCESS AGGREGATE ALSO BACKWARD CACHE CHECKPOINT
94
- CLASS CLUSTER COMMENT COMMENTS CONFIGURATION CONFLICT
95
- CONVERSION COPY COST CSV DATABASE DELIMITER DELIMITERS
96
- DICTIONARY DISABLE DISCARD ENABLE ENCRYPTED ENUM EVENT
97
- EXCLUSIVE EXPLAIN EXTENSION FAMILY FORCE FORWARD FUNCTIONS
98
- HEADER IMMUTABLE IMPLICIT INDEX INDEXES INHERIT INHERITS
99
- INLINE LABEL LEAKPROOF LISTEN LOAD LOCK LOCKED LOGGED
100
- MATERIALIZED MODE MOVE NOTHING NOTIFY NOWAIT OIDS
101
- OPERATOR OWNED OWNER PARSER PASSWORD PLANS POLICY
102
- PREPARED PROCEDURAL PROGRAM QUOTE REASSIGN RECHECK
103
- REFRESH REINDEX RENAME REPLACE REPLICA RESET RULE
104
- SEQUENCES SHARE SHOW SKIP SNAPSHOT STABLE STATISTICS
105
- STDIN STDOUT STORAGE STRICT SYSID TABLES TABLESPACE
106
- TEMP TEMPLATE TEXT TRUSTED TYPES UNENCRYPTED UNLISTEN
107
- UNLOGGED VACUUM VALIDATE VALIDATOR VIEWS VOLATILE
108
- }
109
-
110
- # These keywords cannot be used for type or functions (and should not for columns or tables)
111
- @postgres_key_words_func_type ||= %w{
112
- GREATEST LEAST SETOF XMLROOT
113
- }
114
- super + @postgres_key_words + @postgres_key_words_func_type
115
- end
116
-
117
- def go s = ''
118
- "#{s};\n\n"
119
- end
120
-
121
- def open_escape
122
- '"'
123
- end
124
-
125
- def close_escape
126
- '"'
127
- end
128
-
129
- def index_kind(index)
130
- ''
131
- end
132
-
133
- class PostgresDataTypeContext < SQLDataTypeContext
134
- def integer_ranges
135
- super
136
- end
137
-
138
- def boolean_type
139
- 'BOOLEAN'
140
- end
141
-
142
- def valid_from_type
143
- 'TIMESTAMP'
144
- end
145
-
146
- # There is no performance benefit in using fixed-length CHAR fields,
147
- # and an added burden of trimming the implicitly added white-space
148
- def default_char_type
149
- (@unicode ? 'N' : '') +
150
- 'VARCHAR'
151
- end
152
-
153
- def default_varchar_type
154
- (@unicode ? 'N' : '') +
155
- 'VARCHAR'
156
- end
157
-
158
- def date_time_type
159
- 'TIMESTAMP'
160
- end
161
- end
18
+ prepend Traits::SQL::Postgres
19
+ extend Traits::SQL::Postgres # Needed for class methods, like options
162
20
  end
163
21
 
164
22
  end
@@ -3,13 +3,11 @@
3
3
  #
4
4
  # Copyright (c) 2009-2016 Clifford Heath. Read the LICENSE file.
5
5
  #
6
- # Reserved words gathered from:
7
- # https://technet.microsoft.com/en-us/library/ms189822(v=sql.110).aspx
8
- #
9
6
  require 'digest/sha1'
10
7
  require 'activefacts/metamodel'
11
8
  require 'activefacts/compositions'
12
9
  require 'activefacts/generator/sql'
10
+ require 'activefacts/generator/traits/sql/server'
13
11
 
14
12
  module ActiveFacts
15
13
  module Generators
@@ -17,129 +15,8 @@ module ActiveFacts
17
15
  # * underscore
18
16
  class SQL
19
17
  class Server < SQL
20
- def self.options
21
- super.merge({
22
- # no: [String, "no new options defined here"]
23
- })
24
- end
25
-
26
- def initialize composition, options = {}
27
- super
28
- @closed_world_indices = true
29
- end
30
-
31
- def table_name_max
32
- 128
33
- end
34
-
35
- def data_type_context
36
- SQLServerDataTypeContext.new
37
- end
38
-
39
- def auto_assign_modifier
40
- ' IDENTITY'
41
- end
42
-
43
- def normalise_type(type_name, length, value_constraint, options)
44
- type = MM::DataType.normalise(type_name)
45
- case type
46
- when MM::DataType::TYPE_Money; 'MONEY'
47
- when MM::DataType::TYPE_DateTime; 'DATETIME'
48
- when MM::DataType::TYPE_Timestamp;'DATETIME'
49
- when MM::DataType::TYPE_Binary;
50
- if type_name =~ /^(guid|uuid)$/i && (!length || length == 16)
51
- if ![nil, ''].include?(options[:auto_assign])
52
- options[:default] = ' DEFAULT NEWID()'
53
- options.delete(:auto_assign)
54
- end
55
- return 'UNIQUEIDENTIFIER'
56
- end
57
- if length && length <= 8192
58
- super
59
- else
60
- 'IMAGE'
61
- end
62
- else
63
- super
64
- end
65
- end
66
-
67
- # Reserved words cannot be used anywhere without quoting.
68
- # Keywords have existing definitions, so should not be used without quoting.
69
- # Both lists here are added to the supertype's lists
70
- def reserved_words
71
- @sqlserver_reserved_words ||= %w{
72
- BACKUP BREAK BROWSE BULK CHECKPOINT CLUSTERED COMPUTE
73
- CONTAINSTABLE DATABASE DBCC DENY DISK DISTRIBUTED DUMP
74
- ERRLVL FILE FILLFACTOR FREETEXT FREETEXTTABLE HOLDLOCK
75
- IDENTITYCOL IDENTITY_INSERT INDEX KILL LINENO LOAD
76
- NOCHECK NONCLUSTERED OFF OFFSETS OPENDATASOURCE OPENQUERY
77
- OPENROWSET OPENXML PIVOT PLAN PRINT PROC RAISERROR
78
- READTEXT RECONFIGURE REPLICATION RESTORE REVERT ROWCOUNT
79
- ROWGUIDCOL RULE SAVE SECURITYAUDIT SEMANTICKEYPHRASETABLE
80
- SEMANTICSIMILARITYDETAILSTABLE SEMANTICSIMILARITYTABLE
81
- SETUSER SHUTDOWN STATISTICS TEXTSIZE TOP TRAN TRY_CONVERT
82
- TSEQUAL UNPIVOT UPDATETEXT USE WAITFOR WITHIN GROUP
83
- WRITETEXT
84
- }
85
- super + @sqlserver_reserved_words
86
- end
87
-
88
- def key_words
89
- # These keywords should not be used for columns or tables:
90
- @sqlserver_key_words ||= %w{
91
- INCLUDE INDEX SQLCA
92
- }
93
- super + @sqlserver_key_words
94
- end
95
-
96
- def go s = ''
97
- "#{s}\nGO\n"
98
- end
99
-
100
- def open_escape
101
- '['
102
- end
103
-
104
- def close_escape
105
- ']'
106
- end
107
-
108
- def index_kind(index)
109
- (index.composite_as_primary_index ? ' CLUSTERED' : ' NONCLUSTERED')
110
- end
111
-
112
- class SQLServerDataTypeContext < SQLDataTypeContext
113
- def integer_ranges
114
- [
115
- ['BIT', 0, 1],
116
- ['TINYINT', -2**7, 2**7-1],
117
- ] +
118
- super
119
- end
120
-
121
- def boolean_type
122
- 'BIT'
123
- end
124
-
125
- def valid_from_type
126
- 'DATETIME'
127
- end
128
-
129
- def default_char_type
130
- (@unicode ? 'N' : '') +
131
- 'CHAR'
132
- end
133
-
134
- def default_varchar_type
135
- (@unicode ? 'N' : '') +
136
- 'VARCHAR'
137
- end
138
-
139
- def date_time_type
140
- 'DATETIME'
141
- end
142
- end
18
+ prepend Traits::SQL::Server
19
+ extend Traits::SQL::Server # Needed for class methods, like options
143
20
  end
144
21
 
145
22
  end