tina4ruby 3.13.124 → 3.13.125

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2721edc599a657e8b0e1148215366e11f39c49ee81c8cd3e7a97bec295a558e4
4
- data.tar.gz: 95e143bba0cd72ef76df8bccb15d917a5cc26d09f57e6d23780a7db8a55a3ff9
3
+ metadata.gz: 8b117f25af22a6186fdba82880a24d055a80558f7273d239b9c7478e51b9393d
4
+ data.tar.gz: 0bfb76f6503a503bf19be89cdcf16959a77ffc4d11784f4a519628945e38d4cd
5
5
  SHA512:
6
- metadata.gz: d20ba3ce28b1333d78736a62bc62c938493ee227dc8cee356e35f820c996636111300310501a1ccac272b159163ce5c40cf099c236c1c2aa990be1316c654f59
7
- data.tar.gz: 6ec1241bb4c480869f1def2131c385e5bb03e7264171a36c62a74282ada9558b6a758a92673c29f09cd88c32c502dbe11e6079fdc5b58f2620ae2c49c74f2db9
6
+ metadata.gz: abb84fe5bc77b49b53ef8b6d6ef5139782a5bed7103f88377329a56ef07a376ba3003aecf6d9d3fdd4de4c073ef306b7c467e982acaa6bb451f308e7cf70f13b
7
+ data.tar.gz: 8c760af751f9b0eaee5f659bc90ca5f78505d93b343f89dcdb786fc8404e6376d49800ed05ca39e1c6fa7047d3ed9f0fb0b79480898804d98f1c672893b129c4
data/lib/tina4/cli.rb CHANGED
@@ -143,7 +143,7 @@ module Tina4
143
143
  "bool" => { orm: "boolean_field", sql: "INTEGER", default: "0" },
144
144
  "boolean" => { orm: "boolean_field", sql: "INTEGER", default: "0" },
145
145
  "text" => { orm: "string_field", sql: "TEXT", default: "''" },
146
- "datetime" => { orm: "string_field", sql: "TEXT", default: "NULL" },
146
+ "datetime" => { orm: "string_field", sql: "TIMESTAMP", default: "NULL" },
147
147
  "blob" => { orm: "string_field", sql: "BLOB", default: "NULL" },
148
148
  }.freeze
149
149
 
@@ -2051,7 +2051,7 @@ module Tina4
2051
2051
  default = info[:default] != "NULL" ? " DEFAULT #{info[:default]}" : ""
2052
2052
  col_lines << " #{fname} #{info[:sql]}#{default}"
2053
2053
  end
2054
- col_lines << " created_at TEXT DEFAULT CURRENT_TIMESTAMP"
2054
+ col_lines << " created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP"
2055
2055
 
2056
2056
  # ADR-0063: `-- tina4:edit` marker for the SQL scanner (mirrors `# tina4:edit`
2057
2057
  # in Ruby files). The scanner regex accepts both comment prefixes.
@@ -231,6 +231,17 @@ module Tina4
231
231
  end
232
232
 
233
233
  def execute(sql, params = [])
234
+ # Translate SQLite-canonical DDL to Firebird at APPLY time, mirroring the
235
+ # Python master's firebird.py _translate_sql: strip AUTOINCREMENT (Firebird
236
+ # uses generators), then rewrite the types Firebird rejects -- TEXT ->
237
+ # BLOB SUB_TYPE TEXT (-607), REAL -> DOUBLE PRECISION -- and drop
238
+ # CREATE TABLE IF NOT EXISTS. Both helpers only touch DDL keywords
239
+ # (AUTOINCREMENT / CREATE TABLE / ALTER TABLE), so a plain
240
+ # INSERT/UPDATE/DELETE/SELECT is returned untouched. This is what lets a
241
+ # REALLY-generated migration (id INTEGER PRIMARY KEY AUTOINCREMENT,
242
+ # bio TEXT, price REAL) apply on Firebird instead of raising -607/-104.
243
+ sql = Tina4::SQLTranslator.auto_increment_syntax(sql, "firebird")
244
+ sql = Tina4::SQLTranslator.ddl_types(sql, "firebird")
234
245
  result = with_reconnect do
235
246
  if params.empty?
236
247
  @connection.execute(sql)
@@ -59,6 +59,14 @@ module Tina4
59
59
  end
60
60
 
61
61
  def execute(sql, params = [])
62
+ # Translate SQLite-canonical DDL to T-SQL at APPLY time, mirroring the
63
+ # Python master's mssql.py _translate_sql: AUTOINCREMENT -> IDENTITY(1,1),
64
+ # then strip CREATE TABLE IF NOT EXISTS (not T-SQL) and map TIMESTAMP ->
65
+ # DATETIME2 (MSSQL's TIMESTAMP is a rowversion, not a datetime). Both
66
+ # helpers only touch DDL keywords, so DML is returned untouched -- this is
67
+ # what lets a REALLY-generated migration apply on MSSQL.
68
+ sql = Tina4::SQLTranslator.auto_increment_syntax(sql, "mssql")
69
+ sql = Tina4::SQLTranslator.ddl_types(sql, "mssql")
62
70
  effective_sql = interpolate_params(sql, params)
63
71
 
64
72
  # Capture the generated IDENTITY AT WRITE TIME — mirror of the Python
@@ -73,7 +73,15 @@ module Tina4
73
73
  # wiring that makes the previously-dead concat/ilike helpers live in Ruby.)
74
74
  def translate_dialect(sql)
75
75
  sql = Tina4::SQLTranslator.concat_pipes_to_func(sql)
76
- Tina4::SQLTranslator.ilike_to_like(sql)
76
+ sql = Tina4::SQLTranslator.ilike_to_like(sql)
77
+ # Complete the DDL dialect translation at APPLY time, mirroring the Python
78
+ # master's mysql.py _translate_sql: AUTOINCREMENT -> AUTO_INCREMENT, then
79
+ # map a datetime column's TIMESTAMP -> DATETIME (MySQL's TIMESTAMP carries
80
+ # auto-update + 2038 surprises). Both helpers only touch DDL keywords, so a
81
+ # SELECT/INSERT is returned untouched -- this is what lets a
82
+ # REALLY-generated migration apply on MySQL.
83
+ sql = Tina4::SQLTranslator.auto_increment_syntax(sql, "mysql")
84
+ Tina4::SQLTranslator.ddl_types(sql, "mysql")
77
85
  end
78
86
 
79
87
  def execute_query(sql, params = [])
@@ -233,6 +233,52 @@ module Tina4
233
233
  end
234
234
  end
235
235
 
236
+ # Translate SQLite-canonical DDL column TYPES + CREATE-TABLE options to the
237
+ # target engine.
238
+ #
239
+ # ONLY acts on +CREATE TABLE+ / +ALTER TABLE+ statements, so a query or
240
+ # INSERT that happens to contain the word +TEXT+ (a column name, a string
241
+ # literal) is never rewritten. Complements +auto_increment_syntax+ (which
242
+ # maps the id keyword) so ONE portable migration -- and every
243
+ # +ORM.create_table+ DDL, which is also SQLite-canonical -- applies on every
244
+ # engine instead of failing on Firebird/MSSQL.
245
+ #
246
+ # * Firebird has no +TEXT+ (-607), no +REAL+, and no
247
+ # +CREATE TABLE IF NOT EXISTS+.
248
+ # * MSSQL has no +CREATE TABLE IF NOT EXISTS+ and its +TIMESTAMP+ is a
249
+ # rowversion, not a datetime -- a +created_at TIMESTAMP+ there is wrong.
250
+ # * MySQL's +TIMESTAMP+ carries auto-update / 2038 surprises, so a datetime
251
+ # column maps to +DATETIME+ (matching ORM.create_table).
252
+ #
253
+ # @param sql [String]
254
+ # @param engine [String] firebird, mssql, mysql (others pass through)
255
+ # @return [String]
256
+ def ddl_types(sql, engine)
257
+ # Gate to DDL only, tolerating leading `-- ...` comment lines / blank
258
+ # lines that a migration file carries before its CREATE TABLE. A SELECT
259
+ # or INSERT that merely mentions a type keyword is never rewritten.
260
+ head = sql.sub(/\A(?:\s*--[^\n]*\n)+/, "")
261
+ return sql unless head =~ /\A\s*(?:CREATE\s+TABLE|ALTER\s+TABLE)\b/i
262
+
263
+ case engine.to_s.downcase
264
+ when "firebird"
265
+ sql = sql.gsub(/\bIF\s+NOT\s+EXISTS\b/i, "")
266
+ # Map bare TEXT -> BLOB SUB_TYPE TEXT, but leave an existing
267
+ # "BLOB SUB_TYPE TEXT" intact (it already contains the word TEXT).
268
+ sql = sql.gsub(/\bBLOB\s+SUB_TYPE\s+TEXT\b/i, "\x00FBTEXT\x00")
269
+ sql = sql.gsub(/\bTEXT\b/i, "BLOB SUB_TYPE TEXT")
270
+ sql = sql.gsub("\x00FBTEXT\x00", "BLOB SUB_TYPE TEXT")
271
+ sql.gsub(/\bREAL\b/i, "DOUBLE PRECISION")
272
+ when "mssql"
273
+ sql = sql.gsub(/\bIF\s+NOT\s+EXISTS\b/i, "")
274
+ sql.gsub(/\bTIMESTAMP\b/i, "DATETIME2")
275
+ when "mysql"
276
+ sql.gsub(/\bTIMESTAMP\b/i, "DATETIME")
277
+ else
278
+ sql
279
+ end
280
+ end
281
+
236
282
  # NOTE (SQLTRANS-DEC-02): +placeholder_style+ was removed - every Ruby
237
283
  # driver owns its own placeholder shape (+?+ for MySQL/SQLite/MSSQL/Firebird,
238
284
  # +$1+ for Postgres), so this helper had zero callers and disagreed with the
data/lib/tina4/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tina4
4
- VERSION = "3.13.124"
4
+ VERSION = "3.13.125"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tina4ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.124
4
+ version: 3.13.125
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tina4 Team