From 2337afee15613b656ba250c403506cdb55145c5e Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Mon, 22 Jun 2026 21:20:41 +0200 Subject: [PATCH 1/5] backport: MySQL/MariaDB v3 fixes and extend mysql-unit-full to cover v3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Backports all relevant fixes from PR #1708 to the pgloader v3 CL codebase and extends the mysql-unit-full integration suite to run against v3 (MySQL and MariaDB) using variant expected files for deliberate behavioral differences (serial vs identity, bit vs bit varying, trigger naming). ## v3 fixes ### hex-to-bytea transform (src/utils/transforms.lisp) Add hex-to-bytea: converts plain / 0x-prefixed / \x-prefixed hex strings to PostgreSQL \x... bytea notation. (#1066) ### No-typemod DDL guard (src/pgsql/pgsql-ddl.lisp) Add effective-type-mod: strips typemod for types that don't accept one in PostgreSQL (bytea, boolean, text, date, uuid, json, jsonb, xml, money, oid). Prevents 'type modifier is not allowed for type bytea' errors when a column cast targets bytea but the source typemod is propagated. (#1066) ### first-match-using fix (src/sources/common/casting-rules.lisp) apply-casting-rules was computing first-match-using (the transform from a using-only column cast rule) but never passing it to make-pgsql-type. The finally clause now uses (or using first-match-using) so column-level 'using fn' casts without an explicit 'to TYPE' apply the transform. This is the v3 equivalent of the WITHOUT TYPE feature. (#1522) ### CHECK constraints for MySQL (src/sources/mysql/*) - New list-all-checks.sql: queries information_schema.TABLE_CONSTRAINTS joined with information_schema.CHECK_CONSTRAINTS (MySQL 8.0.16+; returns empty on older servers and MariaDB, safe to run anywhere). - New fetch-check-constraints method: adds constraints to the catalog by replacing MySQL backtick quoting with PostgreSQL double-quote quoting. - New add-check-constraint helper + table-check-constraint-list slot on the table struct (src/utils/catalog.lisp). - New create-pgsql-check-constraints function runs ALTER TABLE ADD CONSTRAINT ... CHECK (...) in the post-load phase (src/pgsql/pgsql-create-schema.lisp, src/load/migrate-database.lisp). (#1645) ### datetime/timestamp/time precision preserved (mysql-cast-rules.lisp) Add :drop-typemod nil to all datetime/timestamp catch-all cast rules so DATETIME(3) maps to timestamptz(3) instead of the no-typemod default of 6. Add explicit time cast rule preserving typemod so TIME(3) maps to time(3). (#1629) ### ON UPDATE CURRENT_TIMESTAMP detection for MySQL 8 (mysql-cast-rules.lisp) MySQL 8 returns 'DEFAULT_GENERATED on update CURRENT_TIMESTAMP' in the EXTRA column; the old pattern only matched 'on update CURRENT_TIMESTAMP'. Fixed with uiop:string-suffix-p so both MySQL 5/8 patterns are recognized. (#1560/#1196) ### CURRENT_TIMESTAMP default case-insensitive (mysql-cast-rules.lisp) MariaDB lowercases the default to 'current_timestamp(6)'; the original check used uiop:string-prefix-p which is case-sensitive. Switch to case-insensitive substring comparison so both MySQL and MariaDB defaults are normalized to :current-timestamp. (#1403) ## Test coverage mysql-unit-full now runs against v3 (MySQL and MariaDB) via new Makefile targets and .v3 / .v3.mariadb variant expected files. Deliberate v3 vs v4 differences captured in variants: - AUTO_INCREMENT → serial (shows nextval default) vs generated identity - BIT(8) → bit (fixed-length) vs bit varying - BIT(1) → boolean vs bit varying - Trigger named on_update_current_timestamp vs trg__All tests pass (MySQL v3, MySQL v4, MariaDB v3, MariaDB v4). --- clojure/tests/mariadb/Makefile | 11 +++-- .../expected/01-tables.v3.mariadb.out | 10 +++++ .../mysql-unit-full/expected/01-tables.v3.out | 10 +++++ .../02-datetime-precision.v3.mariadb.out | 9 +++++ .../expected/02-datetime-precision.v3.out | 9 +++++ .../expected/03-bit-defaults.v3.mariadb.out | 8 ++++ .../expected/03-bit-defaults.v3.out | 8 ++++ .../04-check-constraints.v3.mariadb.out | 6 +++ .../expected/04-check-constraints.v3.out | 6 +++ .../05-on-update-trigger.v3.mariadb.out | 5 +++ .../expected/05-on-update-trigger.v3.out | 5 +++ .../expected/06-hex-to-bytea.v3.mariadb.out | 7 ++++ .../expected/06-hex-to-bytea.v3.out | 7 ++++ .../expected/07-without-type.v3.mariadb.out | 13 ++++++ .../expected/07-without-type.v3.out | 13 ++++++ clojure/tests/mysql/Makefile | 12 ++++-- src/load/migrate-database.lisp | 7 ++++ src/package.lisp | 3 ++ src/pgsql/pgsql-create-schema.lisp | 20 ++++++++++ src/pgsql/pgsql-ddl.lisp | 39 +++++++++++++----- src/sources/common/casting-rules.lisp | 3 +- src/sources/mysql/mysql-cast-rules.lisp | 40 ++++++++++++------- src/sources/mysql/mysql-schema.lisp | 18 +++++++++ src/sources/mysql/mysql.lisp | 3 ++ src/sources/mysql/sql/list-all-checks.sql | 13 ++++++ src/utils/catalog.lisp | 7 ++++ src/utils/transforms.lisp | 14 +++++++ 27 files changed, 272 insertions(+), 34 deletions(-) create mode 100644 clojure/tests/mysql-unit-full/expected/01-tables.v3.mariadb.out create mode 100644 clojure/tests/mysql-unit-full/expected/01-tables.v3.out create mode 100644 clojure/tests/mysql-unit-full/expected/02-datetime-precision.v3.mariadb.out create mode 100644 clojure/tests/mysql-unit-full/expected/02-datetime-precision.v3.out create mode 100644 clojure/tests/mysql-unit-full/expected/03-bit-defaults.v3.mariadb.out create mode 100644 clojure/tests/mysql-unit-full/expected/03-bit-defaults.v3.out create mode 100644 clojure/tests/mysql-unit-full/expected/04-check-constraints.v3.mariadb.out create mode 100644 clojure/tests/mysql-unit-full/expected/04-check-constraints.v3.out create mode 100644 clojure/tests/mysql-unit-full/expected/05-on-update-trigger.v3.mariadb.out create mode 100644 clojure/tests/mysql-unit-full/expected/05-on-update-trigger.v3.out create mode 100644 clojure/tests/mysql-unit-full/expected/06-hex-to-bytea.v3.mariadb.out create mode 100644 clojure/tests/mysql-unit-full/expected/06-hex-to-bytea.v3.out create mode 100644 clojure/tests/mysql-unit-full/expected/07-without-type.v3.mariadb.out create mode 100644 clojure/tests/mysql-unit-full/expected/07-without-type.v3.out create mode 100644 src/sources/mysql/sql/list-all-checks.sql diff --git a/clojure/tests/mariadb/Makefile b/clojure/tests/mariadb/Makefile index 7951805ba..6bd4b17c2 100644 --- a/clojure/tests/mariadb/Makefile +++ b/clojure/tests/mariadb/Makefile @@ -27,10 +27,13 @@ mysql-unit-full: java -jar $(JAR) mysql-unit-full/mysql-unit-full.load java -jar $(JAR) regress $(REGRESS_FLAGS) --variant mariadb mysql-unit-full -# all-v3 explicitly excludes mysql-unit-full: it tests v4-specific behaviour -# and has no meaningful v3 equivalent. The @: recipe prevents the %-v3 -# catch-all from appending its own recipe (make all PGLOADER_CMD=pgloader). -all-v3: my-v3 sakila-v3 f1db-v3 +# mysql-unit-full-v3: same suite against the v3 binary on MariaDB, compared +# against .v3.mariadb variant expected files. +mysql-unit-full-v3: + pgloader --client-min-messages notice mysql-unit-full/mysql-unit-full.load + java -jar $(JAR) regress --variant v3.mariadb mysql-unit-full + +all-v3: my-v3 sakila-v3 f1db-v3 mysql-unit-full-v3 @: %-v3: diff --git a/clojure/tests/mysql-unit-full/expected/01-tables.v3.mariadb.out b/clojure/tests/mysql-unit-full/expected/01-tables.v3.mariadb.out new file mode 100644 index 000000000..f04f62d13 --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/01-tables.v3.mariadb.out @@ -0,0 +1,10 @@ + table_name +---------------- + bit_defaults + hex_binary + on_update_ts + salary_check + set_column + type_precision +(6 rows) + diff --git a/clojure/tests/mysql-unit-full/expected/01-tables.v3.out b/clojure/tests/mysql-unit-full/expected/01-tables.v3.out new file mode 100644 index 000000000..f04f62d13 --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/01-tables.v3.out @@ -0,0 +1,10 @@ + table_name +---------------- + bit_defaults + hex_binary + on_update_ts + salary_check + set_column + type_precision +(6 rows) + diff --git a/clojure/tests/mysql-unit-full/expected/02-datetime-precision.v3.mariadb.out b/clojure/tests/mysql-unit-full/expected/02-datetime-precision.v3.mariadb.out new file mode 100644 index 000000000..17a250ed5 --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/02-datetime-precision.v3.mariadb.out @@ -0,0 +1,9 @@ + column_name | data_type | datetime_precision | column_default +-------------+--------------------------+--------------------+-------------------------------------------- + id | bigint | | nextval('type_precision_id_seq'::regclass) + ts6 | timestamp with time zone | 6 | CURRENT_TIMESTAMP + ts3 | timestamp with time zone | 3 | NULL::timestamp with time zone + t3 | time without time zone | 3 | NULL::time without time zone + plain_ts | timestamp with time zone | 6 | CURRENT_TIMESTAMP +(5 rows) + diff --git a/clojure/tests/mysql-unit-full/expected/02-datetime-precision.v3.out b/clojure/tests/mysql-unit-full/expected/02-datetime-precision.v3.out new file mode 100644 index 000000000..f1c05c3ab --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/02-datetime-precision.v3.out @@ -0,0 +1,9 @@ + column_name | data_type | datetime_precision | column_default +-------------+--------------------------+--------------------+-------------------------------------------- + id | integer | | nextval('type_precision_id_seq'::regclass) + ts6 | timestamp with time zone | 6 | CURRENT_TIMESTAMP + ts3 | timestamp with time zone | 3 | + t3 | time without time zone | 3 | + plain_ts | timestamp with time zone | 6 | CURRENT_TIMESTAMP +(5 rows) + diff --git a/clojure/tests/mysql-unit-full/expected/03-bit-defaults.v3.mariadb.out b/clojure/tests/mysql-unit-full/expected/03-bit-defaults.v3.mariadb.out new file mode 100644 index 000000000..dfbbcb916 --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/03-bit-defaults.v3.mariadb.out @@ -0,0 +1,8 @@ + column_name | data_type | column_default +-------------+--------------------------+------------------------------------------ + id | bigint | nextval('bit_defaults_id_seq'::regclass) + flags | bit | '0'::"bit" + single_bit | boolean | + created_at | timestamp with time zone | CURRENT_TIMESTAMP +(4 rows) + diff --git a/clojure/tests/mysql-unit-full/expected/03-bit-defaults.v3.out b/clojure/tests/mysql-unit-full/expected/03-bit-defaults.v3.out new file mode 100644 index 000000000..5a53267a6 --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/03-bit-defaults.v3.out @@ -0,0 +1,8 @@ + column_name | data_type | column_default +-------------+--------------------------+------------------------------------------ + id | integer | nextval('bit_defaults_id_seq'::regclass) + flags | bit | '0'::"bit" + single_bit | boolean | + created_at | timestamp with time zone | CURRENT_TIMESTAMP +(4 rows) + diff --git a/clojure/tests/mysql-unit-full/expected/04-check-constraints.v3.mariadb.out b/clojure/tests/mysql-unit-full/expected/04-check-constraints.v3.mariadb.out new file mode 100644 index 000000000..8ea7c97f2 --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/04-check-constraints.v3.mariadb.out @@ -0,0 +1,6 @@ + constraint_name | check_clause +---------------------+--------------------------------------- + chk_age_range | CHECK (((age >= 18) AND (age <= 99))) + chk_salary_positive | CHECK ((salary > (0)::numeric)) +(2 rows) + diff --git a/clojure/tests/mysql-unit-full/expected/04-check-constraints.v3.out b/clojure/tests/mysql-unit-full/expected/04-check-constraints.v3.out new file mode 100644 index 000000000..8ea7c97f2 --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/04-check-constraints.v3.out @@ -0,0 +1,6 @@ + constraint_name | check_clause +---------------------+--------------------------------------- + chk_age_range | CHECK (((age >= 18) AND (age <= 99))) + chk_salary_positive | CHECK ((salary > (0)::numeric)) +(2 rows) + diff --git a/clojure/tests/mysql-unit-full/expected/05-on-update-trigger.v3.mariadb.out b/clojure/tests/mysql-unit-full/expected/05-on-update-trigger.v3.mariadb.out new file mode 100644 index 000000000..8c9ecb9f1 --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/05-on-update-trigger.v3.mariadb.out @@ -0,0 +1,5 @@ + trigger_name | event_manipulation | action_timing +-----------------------------+--------------------+--------------- + on_update_current_timestamp | UPDATE | BEFORE +(1 row) + diff --git a/clojure/tests/mysql-unit-full/expected/05-on-update-trigger.v3.out b/clojure/tests/mysql-unit-full/expected/05-on-update-trigger.v3.out new file mode 100644 index 000000000..8c9ecb9f1 --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/05-on-update-trigger.v3.out @@ -0,0 +1,5 @@ + trigger_name | event_manipulation | action_timing +-----------------------------+--------------------+--------------- + on_update_current_timestamp | UPDATE | BEFORE +(1 row) + diff --git a/clojure/tests/mysql-unit-full/expected/06-hex-to-bytea.v3.mariadb.out b/clojure/tests/mysql-unit-full/expected/06-hex-to-bytea.v3.mariadb.out new file mode 100644 index 000000000..c8a6f0682 --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/06-hex-to-bytea.v3.mariadb.out @@ -0,0 +1,7 @@ + label | raw_hex +----------+------------ + plain | \xdeadbeef + prefixed | \xcafebabe + empty | \x +(3 rows) + diff --git a/clojure/tests/mysql-unit-full/expected/06-hex-to-bytea.v3.out b/clojure/tests/mysql-unit-full/expected/06-hex-to-bytea.v3.out new file mode 100644 index 000000000..c8a6f0682 --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/06-hex-to-bytea.v3.out @@ -0,0 +1,7 @@ + label | raw_hex +----------+------------ + plain | \xdeadbeef + prefixed | \xcafebabe + empty | \x +(3 rows) + diff --git a/clojure/tests/mysql-unit-full/expected/07-without-type.v3.mariadb.out b/clojure/tests/mysql-unit-full/expected/07-without-type.v3.mariadb.out new file mode 100644 index 000000000..6a25aace8 --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/07-without-type.v3.mariadb.out @@ -0,0 +1,13 @@ + column_name | data_type | udt_name +-------------+-----------+------------------- + id | bigint | int8 + perms | ARRAY | _set_column_perms +(2 rows) + + id | perms +----+---------------------- + 1 | {read} + 2 | {read,write} + 3 | {read,write,execute} +(3 rows) + diff --git a/clojure/tests/mysql-unit-full/expected/07-without-type.v3.out b/clojure/tests/mysql-unit-full/expected/07-without-type.v3.out new file mode 100644 index 000000000..f238d353d --- /dev/null +++ b/clojure/tests/mysql-unit-full/expected/07-without-type.v3.out @@ -0,0 +1,13 @@ + column_name | data_type | udt_name +-------------+-----------+------------------- + id | integer | int4 + perms | ARRAY | _set_column_perms +(2 rows) + + id | perms +----+---------------------- + 1 | {read} + 2 | {read,write} + 3 | {read,write,execute} +(3 rows) + diff --git a/clojure/tests/mysql/Makefile b/clojure/tests/mysql/Makefile index aad3c6cfe..7ce8ca686 100644 --- a/clojure/tests/mysql/Makefile +++ b/clojure/tests/mysql/Makefile @@ -28,10 +28,14 @@ mysql-unit-full: java -jar $(JAR) mysql-unit-full/mysql-unit-full.load java -jar $(JAR) regress $(REGRESS_FLAGS) mysql-unit-full -# all-v3 explicitly excludes mysql-unit-full: it tests v4-specific behaviour -# and has no meaningful v3 equivalent. The @: recipe prevents the %-v3 -# catch-all from appending its own recipe (make all PGLOADER_CMD=pgloader). -all-v3: my-v3 sakila-v3 f1db-v3 source-v3 +# mysql-unit-full-v3: same suite against the v3 binary, compared against +# .v3 variant expected files that capture deliberate v3 vs v4 differences +# (serial vs identity, bit vs bit varying, trigger naming). +mysql-unit-full-v3: + pgloader --client-min-messages notice mysql-unit-full/mysql-unit-full.load + java -jar $(JAR) regress --variant v3 mysql-unit-full + +all-v3: my-v3 sakila-v3 f1db-v3 source-v3 mysql-unit-full-v3 @: %-v3: diff --git a/src/load/migrate-database.lisp b/src/load/migrate-database.lisp index c12e05060..af4d59c8a 100644 --- a/src/load/migrate-database.lisp +++ b/src/load/migrate-database.lisp @@ -179,6 +179,13 @@ :label "Create Foreign Keys" :log-level :notice)) + ;; + ;; CHECK constraints (MySQL 8.0.16+; no-op when none present) + ;; + (create-pgsql-check-constraints catalog + :section :post + :label "Create Check Constraints") + ;; ;; Triggers and stored procedures -- includes special default values ;; diff --git a/src/package.lisp b/src/package.lisp index b78f3aaf6..159585197 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -101,6 +101,7 @@ #:table-column-list #:table-index-list #:table-fkey-list + #:table-check-constraint-list #:table-trigger-list #:table-citus-rule @@ -193,6 +194,7 @@ #:add-fkey #:find-fkey #:maybe-add-fkey + #:add-check-constraint #:count-tables #:count-views #:count-indexes @@ -459,6 +461,7 @@ #:drop-pgsql-fkeys #:create-pgsql-fkeys #:create-triggers + #:create-pgsql-check-constraints #:fetch-pgsql-catalog #:merge-catalogs diff --git a/src/pgsql/pgsql-create-schema.lisp b/src/pgsql/pgsql-create-schema.lisp index 4ab32dd9c..38969eb6c 100644 --- a/src/pgsql/pgsql-create-schema.lisp +++ b/src/pgsql/pgsql-create-schema.lisp @@ -252,6 +252,26 @@ +;;; +;;; CHECK constraints +;;; +(defun create-pgsql-check-constraints (catalog &key (section :post) label) + "Generate and execute ALTER TABLE … ADD CONSTRAINT … CHECK (…) for every + table that has check constraints recorded in its check-constraint-list." + (let ((sql-list + (loop :for table :in (table-list catalog) + :append + (loop :for (name . clause) :in (table-check-constraint-list table) + :for table-sql := (format nil + "ALTER TABLE ~a ADD CONSTRAINT ~a CHECK (~a);" + (format-table-name table) + (apply-identifier-case name) + clause) + :collect table-sql)))) + (when sql-list + (pgsql-execute-with-timing section label sql-list)))) + + ;;; ;;; Parallel index building. ;;; diff --git a/src/pgsql/pgsql-ddl.lisp b/src/pgsql/pgsql-ddl.lisp index 8b7fc78d8..857b64873 100644 --- a/src/pgsql/pgsql-ddl.lisp +++ b/src/pgsql/pgsql-ddl.lisp @@ -122,6 +122,24 @@ (sqltype-name type-name))))) (string type-name)))) +;;; PostgreSQL types that do not accept a typemod (precision/scale modifier). +;;; When a cast rule preserves the source typemod (drop-typemod nil) but the +;;; target type cannot carry one, the typemod must be silently stripped here +;;; or the CREATE TABLE statement will error with "type modifier is not +;;; allowed for type X". +(defvar *pgsql-no-typemod-types* + '("bytea" "boolean" "bool" "text" "date" "uuid" + "json" "jsonb" "xml" "money" "oid") + "PostgreSQL types that never accept a typemod.") + +(defun effective-type-mod (column) + "Return COLUMN's typemod unless the target type does not support one." + (let ((type-name (get-column-type-name-from-sqltype column))) + (when (and (column-type-mod column) + (not (member type-name *pgsql-no-typemod-types* + :test #'string-equal))) + (column-type-mod column)))) + (defmethod format-create-sql ((column column) &key (stream nil) @@ -129,16 +147,17 @@ pretty-print ((:max-column-name-length max))) (declare (ignore if-not-exists)) - (format stream - "~a~vt~a~:[~*~;~a~]~:[ not null~;~]~:[~; default ~a~]" - (column-name column) - (if pretty-print (if max (+ 3 max) 22) 1) - (get-column-type-name-from-sqltype column) - (column-type-mod column) - (column-type-mod column) - (column-nullable column) - (column-default column) - (format-default-value column))) + (let ((typemod (effective-type-mod column))) + (format stream + "~a~vt~a~:[~*~;~a~]~:[ not null~;~]~:[~; default ~a~]" + (column-name column) + (if pretty-print (if max (+ 3 max) 22) 1) + (get-column-type-name-from-sqltype column) + typemod + typemod + (column-nullable column) + (column-default column) + (format-default-value column)))) (defvar *pgsql-default-values* '((:null . "NULL") diff --git a/src/sources/common/casting-rules.lisp b/src/sources/common/casting-rules.lisp index 9fdd1bd68..e73f44965 100644 --- a/src/sources/common/casting-rules.lisp +++ b/src/sources/common/casting-rules.lisp @@ -165,5 +165,6 @@ :do (when (and (null target) using (null first-match-using)) (setf first-match-using using)) :until target - :finally (return (make-pgsql-type source target using)))))) + :finally (return (make-pgsql-type source target + (or using first-match-using))))))) diff --git a/src/sources/mysql/mysql-cast-rules.lisp b/src/sources/mysql/mysql-cast-rules.lisp index dc8879469..350d89da1 100644 --- a/src/sources/mysql/mysql-cast-rules.lisp +++ b/src/sources/mysql/mysql-cast-rules.lisp @@ -125,35 +125,35 @@ ;; MySQL and dates... ;; (:source (:type "datetime" :default "0000-00-00 00:00:00" :not-null t) - :target (:type "timestamptz" :drop-default t :drop-not-null t) + :target (:type "timestamptz" :drop-default t :drop-not-null t :drop-typemod nil) :using pgloader.transforms::zero-dates-to-null) (:source (:type "datetime" :default "0000-00-00 00:00:00") - :target (:type "timestamptz" :drop-default t) + :target (:type "timestamptz" :drop-default t :drop-typemod nil) :using pgloader.transforms::zero-dates-to-null) (:source (:type "datetime" :on-update-current-timestamp t :not-null t) - :target (:type "timestamptz" :drop-default t :drop-not-null t) + :target (:type "timestamptz" :drop-default t :drop-not-null t :drop-typemod nil) :using pgloader.transforms::zero-dates-to-null) (:source (:type "datetime" :on-update-current-timestamp t :not-null nil) - :target (:type "timestamptz" :drop-default t) + :target (:type "timestamptz" :drop-default t :drop-typemod nil) :using pgloader.transforms::zero-dates-to-null) (:source (:type "timestamp" :default "0000-00-00 00:00:00" :not-null t) - :target (:type "timestamptz" :drop-default t :drop-not-null t) + :target (:type "timestamptz" :drop-default t :drop-not-null t :drop-typemod nil) :using pgloader.transforms::zero-dates-to-null) (:source (:type "timestamp" :default "0000-00-00 00:00:00") - :target (:type "timestamptz" :drop-default t) + :target (:type "timestamptz" :drop-default t :drop-typemod nil) :using pgloader.transforms::zero-dates-to-null) (:source (:type "timestamp" :on-update-current-timestamp t :not-null t) - :target (:type "timestamptz" :drop-default t :drop-not-null t) + :target (:type "timestamptz" :drop-default t :drop-not-null t :drop-typemod nil) :using pgloader.transforms::zero-dates-to-null) (:source (:type "timestamp" :on-update-current-timestamp t :not-null nil) - :target (:type "timestamptz" :drop-default t) + :target (:type "timestamptz" :drop-default t :drop-typemod nil) :using pgloader.transforms::zero-dates-to-null) (:source (:type "date" :default "0000-00-00") @@ -165,13 +165,16 @@ (:source (:type "year") :target (:type "integer" :drop-typemod t)) (:source (:type "datetime") - :target (:type "timestamptz") + :target (:type "timestamptz" :drop-typemod nil) :using pgloader.transforms::zero-dates-to-null) (:source (:type "timestamp") - :target (:type "timestamptz") + :target (:type "timestamptz" :drop-typemod nil) :using pgloader.transforms::zero-dates-to-null) + (:source (:type "time") + :target (:type "time" :drop-typemod nil)) + ;; Inline MySQL "interesting" datatype (:source (:type "enum") :target (:type ,#'enum-or-set-name)) @@ -217,8 +220,12 @@ (cond ((string= "auto_increment" extra) :auto-increment) + ;; MySQL 5.x: plain "on update CURRENT_TIMESTAMP" + ;; MySQL 8.x: "DEFAULT_GENERATED on update CURRENT_TIMESTAMP" ((or (string= extra "on update CURRENT_TIMESTAMP") - (string= extra "on update current_timestamp()")) + (string= extra "on update current_timestamp()") + (uiop:string-suffix-p extra "on update CURRENT_TIMESTAMP") + (uiop:string-suffix-p extra "on update current_timestamp()")) :on-update-current-timestamp))) (defmethod cast ((col mysql-column) &key table) @@ -238,10 +245,13 @@ :null) ((and (stringp default) - ;; address CURRENT_TIMESTAMP(6) and other spellings - (or (uiop:string-prefix-p "CURRENT_TIMESTAMP" default) - (string= "CURRENT TIMESTAMP" default) - (string= "current_timestamp()" default))) + ;; address CURRENT_TIMESTAMP(6) and other spellings. + ;; MySQL 8 uppercases; MariaDB lowercases — use + ;; case-insensitive prefix so both are handled. + (or (string-equal (subseq default 0 + (min 17 (length default))) + "CURRENT_TIMESTAMP") + (string-equal default "CURRENT TIMESTAMP"))) :current-timestamp) (t (column-default pgcol))))) diff --git a/src/sources/mysql/mysql-schema.lisp b/src/sources/mysql/mysql-schema.lisp index fd30aaf7b..a614a5da9 100644 --- a/src/sources/mysql/mysql-schema.lisp +++ b/src/sources/mysql/mysql-schema.lisp @@ -188,6 +188,24 @@ :finally (return schema))) +;;; +;;; MySQL CHECK constraints (MySQL 8.0.16+; no-op on older servers) +;;; +(defmethod fetch-check-constraints ((schema schema) (mysql copy-mysql)) + "Fetch CHECK constraints from MySQL information_schema.CHECK_CONSTRAINTS. + Only available on MySQL 8.0.16+; the JOIN returns empty on older servers + (information_schema.CHECK_CONSTRAINTS was added in 8.0.16)." + (loop + :for (table-name constraint-name check-clause) + :in (mysql-query (sql "/mysql/list-all-checks.sql" (db-name *connection*))) + :do (let ((table (find-table schema table-name))) + (when table + ;; Replace MySQL backtick quoting with PostgreSQL double-quote + ;; quoting so the CHECK clause is valid SQL in PostgreSQL. + (let ((pg-clause (ppcre:regex-replace-all + "`([^`]+)`" check-clause "\"\\1\""))) + (add-check-constraint table constraint-name pg-clause)))))) + ;;; ;;; MySQL table row count estimate ;;; diff --git a/src/sources/mysql/mysql.lisp b/src/sources/mysql/mysql.lisp index b1a15b6ec..1fb53906a 100644 --- a/src/sources/mysql/mysql.lisp +++ b/src/sources/mysql/mysql.lisp @@ -191,6 +191,9 @@ Illegal ~a character starting at position ~a~@[: ~a~].~%" :including including :excluding excluding)) + ;; CHECK constraints (MySQL 8.0.16+ only; no-op on older versions) + (fetch-check-constraints schema mysql) + (when create-indexes (fetch-indexes schema mysql :including including diff --git a/src/sources/mysql/sql/list-all-checks.sql b/src/sources/mysql/sql/list-all-checks.sql new file mode 100644 index 000000000..43a3c8cab --- /dev/null +++ b/src/sources/mysql/sql/list-all-checks.sql @@ -0,0 +1,13 @@ +-- CHECK constraints for a given table. +-- MySQL 8.0.16+ surfaces these in information_schema.CHECK_CONSTRAINTS. +-- On older servers the JOIN returns no rows, so this is safe to run anywhere. +SELECT tc.TABLE_NAME AS table_name, + cc.CONSTRAINT_NAME AS constraint_name, + cc.CHECK_CLAUSE AS check_clause + FROM information_schema.TABLE_CONSTRAINTS tc + JOIN information_schema.CHECK_CONSTRAINTS cc + ON cc.CONSTRAINT_SCHEMA = tc.TABLE_SCHEMA + AND cc.CONSTRAINT_NAME = tc.CONSTRAINT_NAME + WHERE tc.TABLE_SCHEMA = '~a' + AND tc.CONSTRAINT_TYPE = 'CHECK' + ORDER BY tc.TABLE_NAME, cc.CONSTRAINT_NAME diff --git a/src/utils/catalog.lisp b/src/utils/catalog.lisp index a74d67641..7b4ffd140 100644 --- a/src/utils/catalog.lisp +++ b/src/utils/catalog.lisp @@ -57,6 +57,8 @@ index-list fkey-list trigger-list + ;; check-constraint-list: list of (name . pg-clause) pairs + check-constraint-list ;; citus is an extra slot for citus support citus-rule) @@ -421,6 +423,11 @@ (let ((current-fkey (find-fkey table fkey-name :key key :test test))) (or current-fkey (add-fkey table fkey)))) +(defun add-check-constraint (table constraint-name pg-clause) + "Append a CHECK constraint (name . pg-clause) to TABLE's check-constraint-list." + (push-to-end (cons constraint-name pg-clause) + (table-check-constraint-list table))) + ;;; ;;; To report stats to the user, count how many objects we are taking care diff --git a/src/utils/transforms.lisp b/src/utils/transforms.lisp index 49c6f9a94..ab8014a1c 100644 --- a/src/utils/transforms.lisp +++ b/src/utils/transforms.lisp @@ -97,6 +97,7 @@ sql-server-bit-to-boolean varbinary-to-string base64-decode + hex-to-bytea hex-to-dec byte-vector-to-hexstring @@ -500,6 +501,19 @@ (integer hex-string) (string (write-to-string (parse-integer hex-string :radix 16))))) +(defun hex-to-bytea (hex-string) + "Convert a plain or 0x-prefixed hex string to PostgreSQL bytea \\x… notation. + Accepts nil, plain hex (\"deadbeef\"), 0x-prefixed (\"0xdeadbeef\"), + and \\x-prefixed (\"\\xdeadbeef\") inputs." + (etypecase hex-string + (null nil) + (string + (let* ((s (string-trim '(#\Space) hex-string)) + (hex (cond ((uiop:string-prefix-p "0x" s) (subseq s 2)) + ((uiop:string-prefix-p "\\x" s) (subseq s 2)) + (t s)))) + (concatenate 'string "\\x" hex))))) + ;;; ;;; DBF/DB3 transformation functions From 2fcc5d4afe10a9f52ebafdc8966a9c1f38734850 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Mon, 22 Jun 2026 21:50:22 +0200 Subject: [PATCH 2/5] test(mysql): consolidate my+source+mysql-unit-full into unified mytest suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deletes four overlapping MySQL test suites (v4only, my, source, mysql-unit-full) and replaces them with a single mytest suite that loads every table into one MySQL database (pgloader_mytest) and one PostgreSQL schema (mytest). Changes by area: ## Deleted suites - v4only/ — orphaned; seed never loaded; identical SQL + expected output to mysql-unit-full (just different schema name) - my/ — legacy pgloader database; absorbed into mytest - source/ — source/source2 databases; absorbed into mytest - mysql-unit-full is now MySQL-side-only-via-mariadb; MySQL runs mytest ## mytest/mytest.sql (unified seed) All tables from my.sql + history.sql + seed.sql (source + source2) + mysql-unit-full.sql in one pgloader_mytest database. Notable changes: - Expression index uses MySQL-version-gated conditional comment /*!80013 CREATE INDEX ... ((LOWER(email))) */; so MariaDB silently ignores it without a syntax error. - SET SESSION sql_mode='' at the top allows zero-date values in legacy tables (races.date, events.created_at). - ALTER USER ... IDENTIFIED WITH mysql_native_password removed from seed. Kept as a doc comment explaining the qmynd limitation. The container already starts with --default-authentication-plugin=mysql_native_password so the pgloader user is compatible; see load-datasets.sh for the manual command if needed against a plain MySQL 8 instance. - source2.things merged as a plain table; the multi-database aspect is explicitly noted in a comment (see report section below). ## mytest/mytest.load Merged CAST rules from my.load and mysql-unit-full.load. WITH options use the concurrency settings from my.load (2 threads, rows-per-range). ## SQL verification queries (11 total) 01 tables — full merged table list (31 tables) 02 schema — races column types (from old my/sql/02-schema) 03 indexes — non-PK indexes in mytest schema 04 expression-index — lower() expression index exists (MySQL 8.0.13+) 05 camelcase — CamelCaseTable row count + column names 06-11 — from mysql-unit-full (datetime precision, bit defaults, check constraints, on-update trigger, hex-to-bytea, without-type); schema changed to mytest ## Expected files Generated fresh for both v4 (baseline) and v3 (--variant v3). ## Infra updates - Dockerfile: load mytest.sql instead of my.sql + history.sql + seed.sql + mysql-unit-full.sql - load-datasets.sh: single mytest.tmpl step; qmynd doc comment - docker-compose.yml: healthcheck uses pgloader_mytest; mysql-unit-full volume mount removed (no longer needed for MySQL) - Makefile: all → mytest + sakila + f1db + source; mytest-v3 target added ## source2 multi-database scenario (not implemented — see note) The former source2 database existed to test loading from two separate MySQL databases. It has been merged as the things table in pgloader_mytest. There are currently no SQL verification queries that exercise source2 data, so no test coverage is lost. To add a real multi-database test, a second MySQL database (pgloader_mytest_aux) and a second LOAD DATABASE command in the load file would be needed — that is a separate, additive change. --- clojure/tests/mysql/Dockerfile | 26 +- clojure/tests/mysql/Makefile | 26 +- clojure/tests/mysql/data/load-datasets.sh | 26 +- clojure/tests/mysql/data/seed.sql | 111 ----- clojure/tests/mysql/data/v4only.sql | 84 ---- clojure/tests/mysql/docker-compose.yml | 3 +- clojure/tests/mysql/my/my.load | 46 -- .../{my => mytest}/expected/01-tables.out | 16 +- .../mysql/mytest/expected/01-tables.v3.out | 35 ++ .../{my => mytest}/expected/02-schema.out | 0 .../mysql/mytest/expected/02-schema.v3.out | 12 + .../{my => mytest}/expected/03-indexes.out | 19 +- .../mysql/mytest/expected/03-indexes.v3.out | 41 ++ .../expected/04-expression-index.out} | 0 .../expected/04-expression-index.v3.out | 5 + .../expected/05-camelcase.out} | 0 .../mysql/mytest/expected/05-camelcase.v3.out | 11 + .../expected/06-datetime-precision.out} | 0 .../expected/06-datetime-precision.v3.out | 9 + .../expected/07-bit-defaults.out} | 0 .../mytest/expected/07-bit-defaults.v3.out | 8 + .../expected/08-check-constraints.out} | 0 .../expected/08-check-constraints.v3.out | 6 + .../expected/09-on-update-trigger.out} | 0 .../expected/09-on-update-trigger.v3.out | 5 + .../expected/10-hex-to-bytea.out} | 0 .../mytest/expected/10-hex-to-bytea.v3.out | 7 + .../expected/11-without-type.out} | 0 .../mytest/expected/11-without-type.v3.out | 13 + clojure/tests/mysql/mytest/mytest.load | 73 +++ clojure/tests/mysql/mytest/mytest.sql | 417 ++++++++++++++++++ .../mysql/{my => mytest}/sql/01-tables.sql | 3 +- .../mysql/{my => mytest}/sql/02-schema.sql | 3 +- .../mysql/{my => mytest}/sql/03-indexes.sql | 9 +- .../mysql/mytest/sql/04-expression-index.sql | 8 + .../tests/mysql/mytest/sql/05-camelcase.sql | 7 + .../sql/06-datetime-precision.sql} | 2 +- .../sql/07-bit-defaults.sql} | 2 +- .../sql/08-check-constraints.sql} | 2 +- .../sql/09-on-update-trigger.sql} | 2 +- .../sql/10-hex-to-bytea.sql} | 2 +- .../sql/11-without-type.sql} | 4 +- clojure/tests/mysql/source/source.load | 8 - .../mysql/source/sql/01-expression-index.sql | 7 - .../tests/mysql/source/sql/02-camelcase.sql | 7 - .../tests/mysql/v4only/expected/01-tables.out | 10 - clojure/tests/mysql/v4only/sql/01-tables.sql | 6 - clojure/tests/mysql/v4only/v4only.load | 31 -- 48 files changed, 739 insertions(+), 373 deletions(-) delete mode 100644 clojure/tests/mysql/data/seed.sql delete mode 100644 clojure/tests/mysql/data/v4only.sql delete mode 100644 clojure/tests/mysql/my/my.load rename clojure/tests/mysql/{my => mytest}/expected/01-tables.out (63%) create mode 100644 clojure/tests/mysql/mytest/expected/01-tables.v3.out rename clojure/tests/mysql/{my => mytest}/expected/02-schema.out (100%) create mode 100644 clojure/tests/mysql/mytest/expected/02-schema.v3.out rename clojure/tests/mysql/{my => mytest}/expected/03-indexes.out (58%) create mode 100644 clojure/tests/mysql/mytest/expected/03-indexes.v3.out rename clojure/tests/mysql/{source/expected/01-expression-index.out => mytest/expected/04-expression-index.out} (100%) create mode 100644 clojure/tests/mysql/mytest/expected/04-expression-index.v3.out rename clojure/tests/mysql/{source/expected/02-camelcase.out => mytest/expected/05-camelcase.out} (100%) create mode 100644 clojure/tests/mysql/mytest/expected/05-camelcase.v3.out rename clojure/tests/mysql/{v4only/expected/02-datetime-precision.out => mytest/expected/06-datetime-precision.out} (100%) create mode 100644 clojure/tests/mysql/mytest/expected/06-datetime-precision.v3.out rename clojure/tests/mysql/{v4only/expected/03-bit-defaults.out => mytest/expected/07-bit-defaults.out} (100%) create mode 100644 clojure/tests/mysql/mytest/expected/07-bit-defaults.v3.out rename clojure/tests/mysql/{v4only/expected/04-check-constraints.out => mytest/expected/08-check-constraints.out} (100%) create mode 100644 clojure/tests/mysql/mytest/expected/08-check-constraints.v3.out rename clojure/tests/mysql/{v4only/expected/05-on-update-trigger.out => mytest/expected/09-on-update-trigger.out} (100%) create mode 100644 clojure/tests/mysql/mytest/expected/09-on-update-trigger.v3.out rename clojure/tests/mysql/{v4only/expected/06-hex-to-bytea.out => mytest/expected/10-hex-to-bytea.out} (100%) create mode 100644 clojure/tests/mysql/mytest/expected/10-hex-to-bytea.v3.out rename clojure/tests/mysql/{v4only/expected/07-without-type.out => mytest/expected/11-without-type.out} (100%) create mode 100644 clojure/tests/mysql/mytest/expected/11-without-type.v3.out create mode 100644 clojure/tests/mysql/mytest/mytest.load create mode 100644 clojure/tests/mysql/mytest/mytest.sql rename clojure/tests/mysql/{my => mytest}/sql/01-tables.sql (53%) rename clojure/tests/mysql/{my => mytest}/sql/02-schema.sql (56%) rename clojure/tests/mysql/{my => mytest}/sql/03-indexes.sql (55%) create mode 100644 clojure/tests/mysql/mytest/sql/04-expression-index.sql create mode 100644 clojure/tests/mysql/mytest/sql/05-camelcase.sql rename clojure/tests/mysql/{v4only/sql/02-datetime-precision.sql => mytest/sql/06-datetime-precision.sql} (91%) rename clojure/tests/mysql/{v4only/sql/03-bit-defaults.sql => mytest/sql/07-bit-defaults.sql} (91%) rename clojure/tests/mysql/{v4only/sql/04-check-constraints.sql => mytest/sql/08-check-constraints.sql} (93%) rename clojure/tests/mysql/{v4only/sql/05-on-update-trigger.sql => mytest/sql/09-on-update-trigger.sql} (88%) rename clojure/tests/mysql/{v4only/sql/06-hex-to-bytea.sql => mytest/sql/10-hex-to-bytea.sql} (83%) rename clojure/tests/mysql/{v4only/sql/07-without-type.sql => mytest/sql/11-without-type.sql} (85%) delete mode 100644 clojure/tests/mysql/source/source.load delete mode 100644 clojure/tests/mysql/source/sql/01-expression-index.sql delete mode 100644 clojure/tests/mysql/source/sql/02-camelcase.sql delete mode 100644 clojure/tests/mysql/v4only/expected/01-tables.out delete mode 100644 clojure/tests/mysql/v4only/sql/01-tables.sql delete mode 100644 clojure/tests/mysql/v4only/v4only.load diff --git a/clojure/tests/mysql/Dockerfile b/clojure/tests/mysql/Dockerfile index 138a45a7b..7d2494719 100644 --- a/clojure/tests/mysql/Dockerfile +++ b/clojure/tests/mysql/Dockerfile @@ -15,18 +15,13 @@ RUN unzip /tmp/sakila-db.zip -d /tmp/ \ # Download with: test/mysql/download-f1db.sh COPY test/data/f1db.sql /docker-entrypoint-initdb.d/f1db.sql -# === pgloader test schemas (from test/mysql/) === -COPY test/mysql/my.sql /docker-entrypoint-initdb.d/my.sql -COPY test/mysql/history.sql /docker-entrypoint-initdb.d/history.sql - # === db789 materialized views schema (from test/mysql/) === -COPY test/mysql/db789.sql /docker-entrypoint-initdb.d/db789.sql - -# === pgloader integration test seed (source + source2 databases) === -COPY clojure/tests/mysql/data/seed.sql /docker-entrypoint-initdb.d/seed.sql +COPY test/mysql/db789.sql /docker-entrypoint-initdb.d/db789.sql -# === mysql-unit-full test schema (pgloader_mysql_unit_full database) === -COPY clojure/tests/mysql-unit-full/mysql-unit-full.sql /docker-entrypoint-initdb.d/mysql-unit-full.sql +# === Unified pgloader_mytest test schema === +# Combines: legacy "my" + "history" tables, former source/source2 tables, +# and the mysql-unit-full feature tests. See mytest/mytest.sql for details. +COPY clojure/tests/mysql/mytest/mytest.sql /docker-entrypoint-initdb.d/mytest.sql # === Init script === # .sql files renamed to .tmpl to prevent MySQL auto-running them. @@ -35,10 +30,7 @@ COPY clojure/tests/mysql/data/load-datasets.sh /docker-entrypoint-initdb.d/load- RUN chmod +x /docker-entrypoint-initdb.d/load-datasets.sh \ && mv /docker-entrypoint-initdb.d/sakila-schema.sql /docker-entrypoint-initdb.d/sakila-schema.tmpl \ - && mv /docker-entrypoint-initdb.d/sakila-data.sql /docker-entrypoint-initdb.d/sakila-data.tmpl \ - && mv /docker-entrypoint-initdb.d/f1db.sql /docker-entrypoint-initdb.d/f1db.tmpl \ - && mv /docker-entrypoint-initdb.d/my.sql /docker-entrypoint-initdb.d/my.tmpl \ - && mv /docker-entrypoint-initdb.d/history.sql /docker-entrypoint-initdb.d/history.tmpl \ - && mv /docker-entrypoint-initdb.d/db789.sql /docker-entrypoint-initdb.d/db789.tmpl \ - && mv /docker-entrypoint-initdb.d/seed.sql /docker-entrypoint-initdb.d/seed.tmpl \ - && mv /docker-entrypoint-initdb.d/mysql-unit-full.sql /docker-entrypoint-initdb.d/mysql-unit-full.tmpl + && mv /docker-entrypoint-initdb.d/sakila-data.sql /docker-entrypoint-initdb.d/sakila-data.tmpl \ + && mv /docker-entrypoint-initdb.d/f1db.sql /docker-entrypoint-initdb.d/f1db.tmpl \ + && mv /docker-entrypoint-initdb.d/db789.sql /docker-entrypoint-initdb.d/db789.tmpl \ + && mv /docker-entrypoint-initdb.d/mytest.sql /docker-entrypoint-initdb.d/mytest.tmpl diff --git a/clojure/tests/mysql/Makefile b/clojure/tests/mysql/Makefile index 7ce8ca686..0ee6f35aa 100644 --- a/clojure/tests/mysql/Makefile +++ b/clojure/tests/mysql/Makefile @@ -2,13 +2,13 @@ JAR ?= /pgloader.jar PGLOADER_CMD ?= java -jar $(JAR) REGRESS_FLAGS ?= -.PHONY: all my sakila f1db source mysql-unit-full +.PHONY: all mytest sakila f1db source mytest-v3 -all: my sakila f1db source mysql-unit-full +all: mytest sakila f1db source -my: - $(PGLOADER_CMD) my/my.load - java -jar $(JAR) regress $(REGRESS_FLAGS) my +mytest: + $(PGLOADER_CMD) mytest/mytest.load + java -jar $(JAR) regress $(REGRESS_FLAGS) mytest sakila: $(PGLOADER_CMD) sakila/sakila.load @@ -22,20 +22,14 @@ source: $(PGLOADER_CMD) source/source.load java -jar $(JAR) regress $(REGRESS_FLAGS) source -# mysql-unit-full: full v4 regression suite, always run with the v4 JAR. -# Never uses $(PGLOADER_CMD) so it runs with v4 even in mixed environments. -mysql-unit-full: - java -jar $(JAR) mysql-unit-full/mysql-unit-full.load - java -jar $(JAR) regress $(REGRESS_FLAGS) mysql-unit-full - -# mysql-unit-full-v3: same suite against the v3 binary, compared against +# mytest-v3: same suite against the v3 binary, compared against # .v3 variant expected files that capture deliberate v3 vs v4 differences # (serial vs identity, bit vs bit varying, trigger naming). -mysql-unit-full-v3: - pgloader --client-min-messages notice mysql-unit-full/mysql-unit-full.load - java -jar $(JAR) regress --variant v3 mysql-unit-full +mytest-v3: + pgloader --client-min-messages notice mytest/mytest.load + java -jar $(JAR) regress --variant v3 mytest -all-v3: my-v3 sakila-v3 f1db-v3 source-v3 mysql-unit-full-v3 +all-v3: mytest-v3 sakila-v3 f1db-v3 source-v3 @: %-v3: diff --git a/clojure/tests/mysql/data/load-datasets.sh b/clojure/tests/mysql/data/load-datasets.sh index e3c7b94ad..2ef054e89 100644 --- a/clojure/tests/mysql/data/load-datasets.sh +++ b/clojure/tests/mysql/data/load-datasets.sh @@ -10,21 +10,21 @@ echo "=== Loading F1DB dataset (14 tables) ===" mysql -u root -p"$MYSQL_ROOT_PASSWORD" < /docker-entrypoint-initdb.d/f1db.tmpl echo "F1DB loaded successfully" -echo "=== Loading pgloader test schemas (my, history) ===" -mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "CREATE DATABASE IF NOT EXISTS pgloader" -mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "SET GLOBAL sql_mode=''" pgloader -mysql -u root -p"$MYSQL_ROOT_PASSWORD" pgloader < /docker-entrypoint-initdb.d/my.tmpl -mysql -u root -p"$MYSQL_ROOT_PASSWORD" pgloader < /docker-entrypoint-initdb.d/history.tmpl -echo "pgloader test schemas loaded successfully" - echo "=== Loading db789 materialized views schema ===" mysql -u root -p"$MYSQL_ROOT_PASSWORD" < /docker-entrypoint-initdb.d/db789.tmpl echo "db789 loaded successfully" -echo "=== Loading pgloader integration seed (source, source2) ===" -mysql -u root -p"$MYSQL_ROOT_PASSWORD" < /docker-entrypoint-initdb.d/seed.tmpl -echo "Seed loaded successfully" +echo "=== Loading pgloader_mytest unified test schema ===" +# Disable strict mode for the session so legacy zero-date values are accepted. +mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "SET GLOBAL sql_mode=''" +mysql -u root -p"$MYSQL_ROOT_PASSWORD" < /docker-entrypoint-initdb.d/mytest.tmpl +echo "pgloader_mytest loaded successfully" -echo "=== Loading mysql-unit-full test schema (pgloader_mysql_unit_full) ===" -mysql -u root -p"$MYSQL_ROOT_PASSWORD" < /docker-entrypoint-initdb.d/mysql-unit-full.tmpl -echo "mysql-unit-full test schema loaded successfully" +# NOTE — qmynd authentication (pgloader v3 / Common Lisp): +# MySQL 8 defaults to caching_sha2_password, which qmynd does not support. +# This container starts with --default-authentication-plugin=mysql_native_password +# (see docker-compose.yml) so the pgloader user is already compatible. +# If you're running against a plain MySQL 8 without that flag, run: +# +# ALTER USER 'pgloader'@'%' IDENTIFIED WITH mysql_native_password BY 'pgloader'; +# FLUSH PRIVILEGES; diff --git a/clojure/tests/mysql/data/seed.sql b/clojure/tests/mysql/data/seed.sql deleted file mode 100644 index 9e3ed1682..000000000 --- a/clojure/tests/mysql/data/seed.sql +++ /dev/null @@ -1,111 +0,0 @@ -CREATE DATABASE IF NOT EXISTS source; -USE source; - -CREATE TABLE users ( - id INT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(100) NOT NULL, - email VARCHAR(255), - age INT, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE INDEX idx_users_email ON users(email); --- MySQL 8.0 functional/expression index: tests that v4 translates (lower(`email`)) correctly -CREATE INDEX idx_users_email_lower ON users((LOWER(email))); - -INSERT INTO users (name, email, age) VALUES - ('Alice', 'alice@example.com', 30), - ('Bob', 'bob@example.com', 25), - ('Charlie', 'charlie@example.com', 35); - -CREATE TABLE orders ( - id INT AUTO_INCREMENT PRIMARY KEY, - user_id INT NOT NULL, - amount DECIMAL(10,2) NOT NULL, - status ENUM('pending', 'completed', 'cancelled') DEFAULT 'pending', - ordered_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE INDEX idx_orders_user_id ON orders(user_id); - -INSERT INTO orders (user_id, amount, status) VALUES - (1, 99.99, 'completed'), - (2, 49.50, 'pending'), - (1, 149.99, 'completed'); - -ALTER TABLE orders ADD CONSTRAINT fk_orders_user - FOREIGN KEY (user_id) REFERENCES users(id); - -CREATE TABLE type_mapping_test ( - id INT AUTO_INCREMENT PRIMARY KEY, - flag TINYINT(1) DEFAULT 0 COMMENT 'boolean flag: tinyint(1) maps to pg boolean', - small_val TINYINT(4) DEFAULT 0 COMMENT 'regular tinyint maps to smallint', - meta JSON DEFAULT NULL, - boundary GEOMETRY DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -INSERT INTO type_mapping_test (flag, small_val, meta) VALUES - (1, 42, '{"key": "value"}'), - (0, 100, '{"enabled": false}'); - -CREATE TABLE flags ( - id INT AUTO_INCREMENT PRIMARY KEY, - label VARCHAR(50) NOT NULL, - is_active TINYINT(1) NOT NULL DEFAULT 1, - is_visible TINYINT(1) NOT NULL DEFAULT 0 -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -INSERT INTO flags (label, is_active, is_visible) VALUES - ('alpha', 1, 0), - ('beta', 0, 1), - ('gamma', 1, 1); - -CREATE TABLE events ( - id INT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(100), - created_at DATETIME DEFAULT '0000-00-00 00:00:00', - happened DATETIME DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -INSERT INTO events (name, created_at, happened) VALUES - ('zero-date', '0000-00-00 00:00:00', '2024-01-15 10:00:00'), - ('real-date', '2024-03-01 00:00:00', '2024-03-01 12:30:00'); - -CREATE TABLE measurements ( - id INT AUTO_INCREMENT PRIMARY KEY, - label VARCHAR(50), - reading SMALLINT UNSIGNED NOT NULL, - score TINYINT NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -INSERT INTO measurements (label, reading, score) VALUES - ('a', 60000, 100), - ('b', 0, -50), - ('c', 32767, 127); - -CREATE TABLE CamelCaseTable ( - MyId INT AUTO_INCREMENT PRIMARY KEY, - MyName VARCHAR(100) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -INSERT INTO CamelCaseTable (MyName) VALUES ('one'), ('two'); - -CREATE DATABASE IF NOT EXISTS source2; -USE source2; - -CREATE TABLE things (id INT AUTO_INCREMENT PRIMARY KEY, label VARCHAR(50)); -INSERT INTO things (label) VALUES ('foo'), ('bar'); - -USE source; - --- Grant read access to the pgloader user for all source databases -GRANT SELECT ON source.* TO 'pgloader'@'%'; -GRANT SELECT ON source2.* TO 'pgloader'@'%'; -GRANT SELECT ON sakila.* TO 'pgloader'@'%'; -GRANT SELECT ON f1db.* TO 'pgloader'@'%'; -GRANT SELECT ON pgloader.* TO 'pgloader'@'%'; - --- Use mysql_native_password so CL pgloader (qmynd) can authenticate. --- MySQL 8 defaults to caching_sha2_password which qmynd does not support. -ALTER USER 'pgloader'@'%' IDENTIFIED WITH mysql_native_password BY 'pgloader'; -FLUSH PRIVILEGES; diff --git a/clojure/tests/mysql/data/v4only.sql b/clojure/tests/mysql/data/v4only.sql deleted file mode 100644 index a0351d246..000000000 --- a/clojure/tests/mysql/data/v4only.sql +++ /dev/null @@ -1,84 +0,0 @@ --- V4-only test schema: features implemented in the Clojure rewrite that --- have no equivalent in pgloader v3 or produce different output. --- Loaded into the `pgloader_v4` database on MySQL 8.0. - -CREATE DATABASE IF NOT EXISTS pgloader_v4; -USE pgloader_v4; - --- #1629: datetime/timestamp precision modifier preserved (datetime(6) → timestamptz(6)) --- #1403: CURRENT_TIMESTAMP(6) default stripped to current_timestamp -CREATE TABLE type_precision ( - id INT AUTO_INCREMENT PRIMARY KEY, - ts6 DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), - ts3 DATETIME(3) DEFAULT NULL, - t3 TIME(3) DEFAULT NULL, - plain_ts DATETIME DEFAULT CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -INSERT INTO type_precision (ts3, t3) VALUES - ('2024-06-01 12:34:56.123', '01:02:03.456'), - ('2024-12-31 23:59:59.999', '23:59:59.999'); - --- #1280: bit(N) DEFAULT b'0' passes through as bit literal --- #1403: CURRENT_TIMESTAMP default is lowercased keyword (not quoted string) -CREATE TABLE bit_defaults ( - id INT AUTO_INCREMENT PRIMARY KEY, - flags BIT(8) NOT NULL DEFAULT b'00000000', - single_bit BIT(1) NOT NULL DEFAULT b'0', - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -INSERT INTO bit_defaults (flags, single_bit) VALUES - (b'10000001', b'1'), - (b'00000000', b'0'); - --- #1645: CHECK constraints (MySQL 8.0.16+) -CREATE TABLE salary_check ( - id INT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(100) NOT NULL, - salary DECIMAL(10,2) NOT NULL, - age INT NOT NULL, - CONSTRAINT chk_salary_positive CHECK (salary > 0), - CONSTRAINT chk_age_range CHECK (age BETWEEN 18 AND 99) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -INSERT INTO salary_check (name, salary, age) VALUES - ('Alice', 75000.00, 30), - ('Bob', 52000.50, 45); - --- #1560/#1196: ON UPDATE CURRENT_TIMESTAMP → PostgreSQL trigger -CREATE TABLE on_update_ts ( - id INT AUTO_INCREMENT PRIMARY KEY, - payload VARCHAR(200), - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -INSERT INTO on_update_ts (payload) VALUES ('first'), ('second'); - --- #1066: hex-to-bytea cast function --- Store hex strings that should land in PostgreSQL as bytea \x... -CREATE TABLE hex_binary ( - id INT AUTO_INCREMENT PRIMARY KEY, - label VARCHAR(50), - raw_hex VARCHAR(255) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -INSERT INTO hex_binary (label, raw_hex) VALUES - ('plain', 'DEADBEEF'), - ('prefixed', '0xCAFEBABE'), - ('empty', ''); - --- #1522: WITHOUT TYPE cast syntax --- The `status` column uses WITHOUT TYPE so the pgloader SET type is kept --- as text[] in PostgreSQL, applying only the cast function (set-to-enum-array). -CREATE TABLE set_column ( - id INT AUTO_INCREMENT PRIMARY KEY, - perms SET('read','write','execute') NOT NULL DEFAULT 'read' -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -INSERT INTO set_column (perms) VALUES ('read'), ('read,write'), ('read,write,execute'); - --- Grant access to the pgloader user -GRANT SELECT ON pgloader_v4.* TO 'pgloader'@'%'; -FLUSH PRIVILEGES; diff --git a/clojure/tests/mysql/docker-compose.yml b/clojure/tests/mysql/docker-compose.yml index 1f2591124..d0972f1e7 100644 --- a/clojure/tests/mysql/docker-compose.yml +++ b/clojure/tests/mysql/docker-compose.yml @@ -22,7 +22,7 @@ services: MYSQL_USER: pgloader MYSQL_PASSWORD: pgloader healthcheck: - test: ["CMD-SHELL", "mysql -u root -prootpassword -e 'USE source; SELECT COUNT(*) FROM users' 2>/dev/null && mysql -u root -prootpassword -e 'USE sakila; SELECT COUNT(*) FROM actor' 2>/dev/null && mysql -u root -prootpassword -e 'USE f1db; SELECT COUNT(*) FROM circuits' 2>/dev/null && mysql -u root -prootpassword -e 'USE pgloader_mysql_unit_full; SELECT COUNT(*) FROM salary_check' 2>/dev/null"] + test: ["CMD-SHELL", "mysql -u root -prootpassword -e 'USE pgloader_mytest; SELECT COUNT(*) FROM users' 2>/dev/null && mysql -u root -prootpassword -e 'USE sakila; SELECT COUNT(*) FROM actor' 2>/dev/null && mysql -u root -prootpassword -e 'USE f1db; SELECT COUNT(*) FROM circuits' 2>/dev/null"] interval: 10s timeout: 10s retries: 30 @@ -34,7 +34,6 @@ services: dockerfile: clojure/tests/Dockerfile volumes: - .:/suite - - ../mysql-unit-full:/suite/mysql-unit-full - ../../target/pgloader.jar:/pgloader.jar:ro environment: JAR: /pgloader.jar diff --git a/clojure/tests/mysql/my/my.load b/clojure/tests/mysql/my/my.load deleted file mode 100644 index 33689d5ff..000000000 --- a/clojure/tests/mysql/my/my.load +++ /dev/null @@ -1,46 +0,0 @@ -load database - from mysql://root:rootpassword@mysql:3306/pgloader?useSSL=false - into postgresql://pgloader:pgloader@postgres:5432/target - - WITH concurrency = 2, - multiple readers per thread, - rows per range = 50000, - quote identifiers - - ALTER SCHEMA 'pgloader' RENAME TO 'mysql' - ALTER TABLE NAMES MATCHING ~/./ SET TABLESPACE 'pg_default' - - -- INCLUDING ONLY TABLE NAMES MATCHING 'encryption_key_canary' - - CAST column utilisateurs__Yvelines2013-06-28.sexe - to text drop not null using empty-string-to-null, - - column funny_string.s to text drop typemod drop not null, - - column base64.id to uuid drop typemod, - column base64.data to jsonb using base64-decode, - - -- This is now a default casting rule for MySQL - -- type bigint when signed to bigint drop typemod, - - type decimal - when (and (= 18 precision) (= 6 scale)) - to "double precision" drop typemod, - - type smallint when unsigned to int drop typemod, - - type timestamp - when default "CURRENT_TIMESTAMP" - with extra on update current timestamp - to "timestamp with time zone" - drop default drop not null drop extra - using zero-dates-to-null, - - type timestamp with extra on update current timestamp - to "timestamp with time zone" drop extra, - - column encryption_key_canary.uuid - to uuid drop typemod using byte-vector-to-hexstring - - BEFORE LOAD DO - $$ create schema if not exists mysql; $$; diff --git a/clojure/tests/mysql/my/expected/01-tables.out b/clojure/tests/mysql/mytest/expected/01-tables.out similarity index 63% rename from clojure/tests/mysql/my/expected/01-tables.out rename to clojure/tests/mysql/mytest/expected/01-tables.out index 2aa53ce56..07dcd715f 100644 --- a/clojure/tests/mysql/my/expected/01-tables.out +++ b/clojure/tests/mysql/mytest/expected/01-tables.out @@ -1,21 +1,35 @@ table_name ---------------------------------- CamelCase + CamelCaseTable base64 + bit_defaults bits countdata_template domain_filter empty encryption_key_canary + events fcm_batches + flags funny_string geom + hex_binary history + measurements + on_update_ts onupdate + orders pgloader_test_unsigned propertydecimal races + salary_check + set_column + things + type_mapping_test + type_precision + users utilisateurs__Yvelines2013-06-28 uw_defined_meaning -(17 rows) +(31 rows) diff --git a/clojure/tests/mysql/mytest/expected/01-tables.v3.out b/clojure/tests/mysql/mytest/expected/01-tables.v3.out new file mode 100644 index 000000000..07dcd715f --- /dev/null +++ b/clojure/tests/mysql/mytest/expected/01-tables.v3.out @@ -0,0 +1,35 @@ + table_name +---------------------------------- + CamelCase + CamelCaseTable + base64 + bit_defaults + bits + countdata_template + domain_filter + empty + encryption_key_canary + events + fcm_batches + flags + funny_string + geom + hex_binary + history + measurements + on_update_ts + onupdate + orders + pgloader_test_unsigned + propertydecimal + races + salary_check + set_column + things + type_mapping_test + type_precision + users + utilisateurs__Yvelines2013-06-28 + uw_defined_meaning +(31 rows) + diff --git a/clojure/tests/mysql/my/expected/02-schema.out b/clojure/tests/mysql/mytest/expected/02-schema.out similarity index 100% rename from clojure/tests/mysql/my/expected/02-schema.out rename to clojure/tests/mysql/mytest/expected/02-schema.out diff --git a/clojure/tests/mysql/mytest/expected/02-schema.v3.out b/clojure/tests/mysql/mytest/expected/02-schema.v3.out new file mode 100644 index 000000000..41fb815b3 --- /dev/null +++ b/clojure/tests/mysql/mytest/expected/02-schema.v3.out @@ -0,0 +1,12 @@ + column_name | data_type +-------------+------------------------ + raceId | integer + year | integer + round | integer + circuitId | integer + name | character varying + date | date + time | time without time zone + url | character varying +(8 rows) + diff --git a/clojure/tests/mysql/my/expected/03-indexes.out b/clojure/tests/mysql/mytest/expected/03-indexes.out similarity index 58% rename from clojure/tests/mysql/my/expected/03-indexes.out rename to clojure/tests/mysql/mytest/expected/03-indexes.out index 1ccfec73b..a861d0aa0 100644 --- a/clojure/tests/mysql/my/expected/03-indexes.out +++ b/clojure/tests/mysql/mytest/expected/03-indexes.out @@ -1,5 +1,19 @@ indexname ---------------------------------------- + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY idx_{oid}_PRIMARY idx_{oid}_PRIMARY idx_{oid}_PRIMARY @@ -16,9 +30,12 @@ idx_{oid}_domain_filter_unq idx_{oid}_fcm_batches_created_at_index idx_{oid}_hotel_id + idx_{oid}_idx_orders_user_id + idx_{oid}_idx_users_email + idx_{oid}_idx_users_email_lower idx_{oid}_patient_id idx_{oid}_search idx_{oid}_update_type idx_{oid}_url -(20 rows) +(37 rows) diff --git a/clojure/tests/mysql/mytest/expected/03-indexes.v3.out b/clojure/tests/mysql/mytest/expected/03-indexes.v3.out new file mode 100644 index 000000000..a861d0aa0 --- /dev/null +++ b/clojure/tests/mysql/mytest/expected/03-indexes.v3.out @@ -0,0 +1,41 @@ + indexname +---------------------------------------- + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_PRIMARY + idx_{oid}_ak_countdata_idx + idx_{oid}_domain_filter + idx_{oid}_domain_filter_unq + idx_{oid}_fcm_batches_created_at_index + idx_{oid}_hotel_id + idx_{oid}_idx_orders_user_id + idx_{oid}_idx_users_email + idx_{oid}_idx_users_email_lower + idx_{oid}_patient_id + idx_{oid}_search + idx_{oid}_update_type + idx_{oid}_url +(37 rows) + diff --git a/clojure/tests/mysql/source/expected/01-expression-index.out b/clojure/tests/mysql/mytest/expected/04-expression-index.out similarity index 100% rename from clojure/tests/mysql/source/expected/01-expression-index.out rename to clojure/tests/mysql/mytest/expected/04-expression-index.out diff --git a/clojure/tests/mysql/mytest/expected/04-expression-index.v3.out b/clojure/tests/mysql/mytest/expected/04-expression-index.v3.out new file mode 100644 index 000000000..927cf8ae7 --- /dev/null +++ b/clojure/tests/mysql/mytest/expected/04-expression-index.v3.out @@ -0,0 +1,5 @@ + has_expression +---------------- + t +(1 row) + diff --git a/clojure/tests/mysql/source/expected/02-camelcase.out b/clojure/tests/mysql/mytest/expected/05-camelcase.out similarity index 100% rename from clojure/tests/mysql/source/expected/02-camelcase.out rename to clojure/tests/mysql/mytest/expected/05-camelcase.out diff --git a/clojure/tests/mysql/mytest/expected/05-camelcase.v3.out b/clojure/tests/mysql/mytest/expected/05-camelcase.v3.out new file mode 100644 index 000000000..dcb909417 --- /dev/null +++ b/clojure/tests/mysql/mytest/expected/05-camelcase.v3.out @@ -0,0 +1,11 @@ + count +------- + 2 +(1 row) + + column_name +------------- + MyId + MyName +(2 rows) + diff --git a/clojure/tests/mysql/v4only/expected/02-datetime-precision.out b/clojure/tests/mysql/mytest/expected/06-datetime-precision.out similarity index 100% rename from clojure/tests/mysql/v4only/expected/02-datetime-precision.out rename to clojure/tests/mysql/mytest/expected/06-datetime-precision.out diff --git a/clojure/tests/mysql/mytest/expected/06-datetime-precision.v3.out b/clojure/tests/mysql/mytest/expected/06-datetime-precision.v3.out new file mode 100644 index 000000000..f1c05c3ab --- /dev/null +++ b/clojure/tests/mysql/mytest/expected/06-datetime-precision.v3.out @@ -0,0 +1,9 @@ + column_name | data_type | datetime_precision | column_default +-------------+--------------------------+--------------------+-------------------------------------------- + id | integer | | nextval('type_precision_id_seq'::regclass) + ts6 | timestamp with time zone | 6 | CURRENT_TIMESTAMP + ts3 | timestamp with time zone | 3 | + t3 | time without time zone | 3 | + plain_ts | timestamp with time zone | 6 | CURRENT_TIMESTAMP +(5 rows) + diff --git a/clojure/tests/mysql/v4only/expected/03-bit-defaults.out b/clojure/tests/mysql/mytest/expected/07-bit-defaults.out similarity index 100% rename from clojure/tests/mysql/v4only/expected/03-bit-defaults.out rename to clojure/tests/mysql/mytest/expected/07-bit-defaults.out diff --git a/clojure/tests/mysql/mytest/expected/07-bit-defaults.v3.out b/clojure/tests/mysql/mytest/expected/07-bit-defaults.v3.out new file mode 100644 index 000000000..5a53267a6 --- /dev/null +++ b/clojure/tests/mysql/mytest/expected/07-bit-defaults.v3.out @@ -0,0 +1,8 @@ + column_name | data_type | column_default +-------------+--------------------------+------------------------------------------ + id | integer | nextval('bit_defaults_id_seq'::regclass) + flags | bit | '0'::"bit" + single_bit | boolean | + created_at | timestamp with time zone | CURRENT_TIMESTAMP +(4 rows) + diff --git a/clojure/tests/mysql/v4only/expected/04-check-constraints.out b/clojure/tests/mysql/mytest/expected/08-check-constraints.out similarity index 100% rename from clojure/tests/mysql/v4only/expected/04-check-constraints.out rename to clojure/tests/mysql/mytest/expected/08-check-constraints.out diff --git a/clojure/tests/mysql/mytest/expected/08-check-constraints.v3.out b/clojure/tests/mysql/mytest/expected/08-check-constraints.v3.out new file mode 100644 index 000000000..8ea7c97f2 --- /dev/null +++ b/clojure/tests/mysql/mytest/expected/08-check-constraints.v3.out @@ -0,0 +1,6 @@ + constraint_name | check_clause +---------------------+--------------------------------------- + chk_age_range | CHECK (((age >= 18) AND (age <= 99))) + chk_salary_positive | CHECK ((salary > (0)::numeric)) +(2 rows) + diff --git a/clojure/tests/mysql/v4only/expected/05-on-update-trigger.out b/clojure/tests/mysql/mytest/expected/09-on-update-trigger.out similarity index 100% rename from clojure/tests/mysql/v4only/expected/05-on-update-trigger.out rename to clojure/tests/mysql/mytest/expected/09-on-update-trigger.out diff --git a/clojure/tests/mysql/mytest/expected/09-on-update-trigger.v3.out b/clojure/tests/mysql/mytest/expected/09-on-update-trigger.v3.out new file mode 100644 index 000000000..8c9ecb9f1 --- /dev/null +++ b/clojure/tests/mysql/mytest/expected/09-on-update-trigger.v3.out @@ -0,0 +1,5 @@ + trigger_name | event_manipulation | action_timing +-----------------------------+--------------------+--------------- + on_update_current_timestamp | UPDATE | BEFORE +(1 row) + diff --git a/clojure/tests/mysql/v4only/expected/06-hex-to-bytea.out b/clojure/tests/mysql/mytest/expected/10-hex-to-bytea.out similarity index 100% rename from clojure/tests/mysql/v4only/expected/06-hex-to-bytea.out rename to clojure/tests/mysql/mytest/expected/10-hex-to-bytea.out diff --git a/clojure/tests/mysql/mytest/expected/10-hex-to-bytea.v3.out b/clojure/tests/mysql/mytest/expected/10-hex-to-bytea.v3.out new file mode 100644 index 000000000..c8a6f0682 --- /dev/null +++ b/clojure/tests/mysql/mytest/expected/10-hex-to-bytea.v3.out @@ -0,0 +1,7 @@ + label | raw_hex +----------+------------ + plain | \xdeadbeef + prefixed | \xcafebabe + empty | \x +(3 rows) + diff --git a/clojure/tests/mysql/v4only/expected/07-without-type.out b/clojure/tests/mysql/mytest/expected/11-without-type.out similarity index 100% rename from clojure/tests/mysql/v4only/expected/07-without-type.out rename to clojure/tests/mysql/mytest/expected/11-without-type.out diff --git a/clojure/tests/mysql/mytest/expected/11-without-type.v3.out b/clojure/tests/mysql/mytest/expected/11-without-type.v3.out new file mode 100644 index 000000000..f238d353d --- /dev/null +++ b/clojure/tests/mysql/mytest/expected/11-without-type.v3.out @@ -0,0 +1,13 @@ + column_name | data_type | udt_name +-------------+-----------+------------------- + id | integer | int4 + perms | ARRAY | _set_column_perms +(2 rows) + + id | perms +----+---------------------- + 1 | {read} + 2 | {read,write} + 3 | {read,write,execute} +(3 rows) + diff --git a/clojure/tests/mysql/mytest/mytest.load b/clojure/tests/mysql/mytest/mytest.load new file mode 100644 index 000000000..8fdce3e34 --- /dev/null +++ b/clojure/tests/mysql/mytest/mytest.load @@ -0,0 +1,73 @@ +-- Unified MySQL regression load file. +-- Loads the pgloader_mytest database (seed: mytest/mytest.sql) into PostgreSQL. +-- Covers: legacy type-mapping edge cases (issues #650–#1102), the source/source2 +-- tables (expression index, camelCase), and the feature tests introduced in v4 +-- (issues #1066, #1196, #1280, #1403, #1522, #1560, #1629, #1645). + +load database + from mysql://root:rootpassword@mysql:3306/pgloader_mytest?useSSL=false + into postgresql://pgloader:pgloader@postgres:5432/target + + WITH concurrency = 2, + multiple readers per thread, + rows per range = 50000, + quote identifiers, + create tables, + create indexes, + include drop + + ALTER SCHEMA 'pgloader_mytest' RENAME TO 'mytest' + ALTER TABLE NAMES MATCHING ~/./ SET TABLESPACE 'pg_default' + + CAST + -- -------------------------------------------------------- + -- Legacy "my" database cast rules + -- -------------------------------------------------------- + + -- issue #650: enum with empty string values → NULL + column utilisateurs__Yvelines2013-06-28.sexe + to text drop not null using empty-string-to-null, + + -- issue #661: funny_string.s has no meaningful typemod + column funny_string.s to text drop typemod drop not null, + + -- issue #904: binary(16) uuid stored as hex blob → PostgreSQL uuid + column base64.id to uuid drop typemod, + column base64.data to jsonb using base64-decode, + + -- decimal(18,6) used as double precision + type decimal + when (and (= 18 precision) (= 6 scale)) + to "double precision" drop typemod, + + -- unsigned smallint overflows PostgreSQL smallint range → int + type smallint when unsigned to int drop typemod, + + -- ON UPDATE CURRENT_TIMESTAMP: zero-date variant (drop the broken default) + type timestamp + when default "CURRENT_TIMESTAMP" + with extra on update current timestamp + to "timestamp with time zone" + drop default drop not null drop extra + using zero-dates-to-null, + + -- ON UPDATE CURRENT_TIMESTAMP: plain variant (keep default, drop extra) + type timestamp with extra on update current timestamp + to "timestamp with time zone" drop extra, + + -- issue #904: binary(16) uuid → PostgreSQL uuid type + column encryption_key_canary.uuid + to uuid drop typemod using byte-vector-to-hexstring, + + -- -------------------------------------------------------- + -- mysql-unit-full feature cast rules + -- -------------------------------------------------------- + + -- #1066: raw_hex column contains hex strings → PostgreSQL bytea \x... + column hex_binary.raw_hex to bytea using hex-to-bytea, + + -- #1522: WITHOUT TYPE — preserve SET→text[] mapping, apply transform only + column set_column.perms using set-to-enum-array + + BEFORE LOAD DO + $$ CREATE SCHEMA IF NOT EXISTS mytest; $$; diff --git a/clojure/tests/mysql/mytest/mytest.sql b/clojure/tests/mysql/mytest/mytest.sql new file mode 100644 index 000000000..5b4528882 --- /dev/null +++ b/clojure/tests/mysql/mytest/mytest.sql @@ -0,0 +1,417 @@ +-- Unified integration test seed for pgloader MySQL regression suite. +-- Combines: the legacy "my" test database, the mysql-unit-full feature tests, +-- and the former source/source2 databases — all in a single MySQL database. +-- +-- Compatible with MySQL 8.0.16+ and MariaDB 10.2+. +-- Uses MySQL-version-gated conditional comments (/*!NNNNN ... */) where +-- a feature is unavailable on older servers or on MariaDB. +-- +-- NOTE — qmynd authentication (pgloader v3 / CL): +-- MySQL 8 defaults to caching_sha2_password, which the qmynd library does +-- not support. The docker-compose service starts MySQL with +-- --default-authentication-plugin=mysql_native_password +-- so the pgloader user created by MYSQL_USER is already compatible. +-- If you're connecting qmynd against a plain MySQL 8 instance (no flag), +-- run manually: +-- ALTER USER 'pgloader'@'%' IDENTIFIED WITH mysql_native_password BY 'pgloader'; +-- FLUSH PRIVILEGES; + +CREATE DATABASE IF NOT EXISTS pgloader_mytest; + +-- Disable strict mode for this session so zero-date values in legacy tables +-- (races.date DEFAULT '0000-00-00', events.created_at DEFAULT '0000-00-00 00:00:00') +-- are accepted without error. +SET SESSION sql_mode=''; + +USE pgloader_mytest; + +-- ============================================================ +-- Legacy "my" tables (originally in the pgloader database) +-- These cover edge cases accumulated from reported pgloader bugs. +-- ============================================================ + +CREATE TABLE `empty` (id integer AUTO_INCREMENT PRIMARY KEY); + +-- races: basic table with date/time columns and a MyISAM engine +CREATE TABLE `races` ( + `raceId` int(11) NOT NULL AUTO_INCREMENT, + `year` int(11) NOT NULL DEFAULT 0, + `round` int(11) NOT NULL DEFAULT 0, + `circuitId` int(11) NOT NULL DEFAULT 0, + `name` varchar(255) NOT NULL DEFAULT '', + `date` date NOT NULL DEFAULT '0000-00-00', + `time` time DEFAULT NULL, + `url` varchar(255) DEFAULT NULL, + PRIMARY KEY (`raceId`), + UNIQUE KEY `url` (`url`) +) ENGINE=MyISAM AUTO_INCREMENT=989 DEFAULT CHARSET=utf8; + +-- utilisateurs: issue #650 — enum with unicode values, non-ASCII table name +CREATE TABLE `utilisateurs__Yvelines2013-06-28` ( + `statut` enum('administrateur','odis','pilote','bureau','relais','stagiaire','membre','participant','contact') COLLATE utf8_unicode_ci NOT NULL, + `anciennete` year(4) DEFAULT NULL, + `sexe` enum('H','F') COLLATE utf8_unicode_ci DEFAULT NULL, + `categorie` enum('Exploitant agricole','Artisan, commerçant, chef d''entreprise','Cadre, profession intellectuelle supérieure','Profession intermédiaire','Employé','Ouvrier','Retraité','Étudiant','Sans activité professionnelle') COLLATE utf8_unicode_ci DEFAULT NULL, + `secteur` enum('Secteur privé - Industrie','Secteur privé - Services','Secteur privé - Agriculture','Fonction publique d''Etat','Fonction publique hospitalière','Fonction publique territoriale','Secteur associatif et social') COLLATE utf8_unicode_ci DEFAULT NULL, + `nombre` enum('0','1','2','3 ?? 5','6 ?? 9','10 ?? 19','20 ?? 49','50 ?? 99','100 ?? 199','200 ?? 499','500 ?? 999','1 000 ?? 4 999','5 000 ?? 9 999','10 000 et plus') COLLATE utf8_unicode_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- geom: geometry columns +CREATE TABLE `geom` ( + id integer AUTO_INCREMENT PRIMARY KEY, + p point, + l linestring +); + +INSERT INTO `geom` (`p`, `l`) VALUES ( + ST_GeomFromText('POINT(1 1)'), + ST_GeomFromText('LINESTRING(-87.87342467651445 45.79684462673078,-87.87170806274479 45.802110434248966,-87.84492888794016 45.79732335706963,-87.84046569213925 45.79349339919981,-87.83703246459994 45.795887153715135,-87.82261290893646 45.7954084110377,-87.82261290893646 45.781523084289475,-87.82879271850615 45.7796075953549,-87.84115233764729 45.779128712838755,-87.85110869751074 45.78008647375808,-87.83737578735439 45.782001946240946,-87.84527221069374 45.78343850741725)') +); + +-- propertydecimal: issue #650 — decimal(18,0) / decimal(18,6) type mapping +CREATE TABLE propertydecimal ( + ID decimal(18,0) NOT NULL, + propertyvalue decimal(18,6) DEFAULT NULL, + PRIMARY KEY (ID) +); + +-- base64: issue #650 — base64 encoded JSON in longtext column → jsonb +CREATE TABLE `base64` ( + id varchar(255), + data longtext +) COMMENT 'Test decoding base64 documents'; + +INSERT INTO `base64` (id, data) VALUES ( + '65de699d-b5cc-4e13-b507-c71adea31e53', + 'eyJrZXkiOiAidmFsdWUifQ==' +); + +-- onupdate: ON UPDATE CURRENT_TIMESTAMP in the legacy "my" database +-- (distinct from on_update_ts below which tests the v4 trigger generation) +CREATE TABLE `onupdate` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `patient_id` varchar(50) NOT NULL, + `calc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `update_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `patient_id` (`patient_id`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; + +-- funny_string: issue #661 — CREATE TABLE AS SELECT with GBK charset +CREATE TABLE funny_string AS SELECT char(41856 USING 'gbk') AS s; + +-- pgloader_test_unsigned: issue #678 — UNSIGNED integer type mapping +CREATE TABLE pgloader_test_unsigned ( + id SMALLINT UNSIGNED, + sm smallint, + tu TINYINT UNSIGNED +); +INSERT INTO pgloader_test_unsigned (id) VALUES (65535); + +-- bits: issue #684 — bit(1) → boolean +CREATE TABLE bits ( + id integer NOT NULL AUTO_INCREMENT PRIMARY KEY, + bool bit(1) +); +INSERT INTO bits (bool) VALUES (0b00), (0b01); + +-- domain_filter: issue #811 — binary/varbinary/json columns, ON UPDATE CURRENT_TIMESTAMP +CREATE TABLE `domain_filter` ( + `id` binary(16) NOT NULL, + `type` varchar(50) NOT NULL, + `value` json DEFAULT NULL, + `negated` tinyint(1) NOT NULL DEFAULT '0', + `report_id` varbinary(255) NOT NULL, + `query_id` varchar(255) NOT NULL, + `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `updated_by` varbinary(255) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `domain_filter_unq` (`report_id`, `query_id`, `type`), + KEY `domain_filter` (`type`) +) ENGINE=InnoDB DEFAULT CHARSET=ascii; + +-- encryption_key_canary: issue #904 — binary(16) uuid, blob columns +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `encryption_key_canary` ( + `encrypted_value` blob, + `nonce` tinyblob, + `uuid` binary(16) NOT NULL, + `salt` tinyblob, + PRIMARY KEY (`uuid`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + +LOCK TABLES `encryption_key_canary` WRITE; +/*!40000 ALTER TABLE `encryption_key_canary` DISABLE KEYS */; +INSERT INTO `encryption_key_canary` VALUES ( + 0x1F36F183D7EE47C71453850B756945C16D9D711B2F0594E5D5E54D1EC94E081716AB8642AA60F84B50F69454D098122B7136A0DEB3AF200C2C5C7500BDFA0BD9689CCBF10A76972374882B304F7F15A227E815989FC87EEB72612396F569C662E72A2A7555E654605A3B83C1C753297832E52C5961E81EBC60DC43D929ABAB8CB14601DEFED121604CEB26210AB6D724, + 0x044AA707DF17021E55E9A1E4, + 0x88C2982F428A46B7B71B210618AE1658, + 0xAE7F18028E7984FB5630F7D23FB77999C6CA7CF5355EF0194F3F16521EA7EC503F566229ED8DC5EFBBE9C12BA491BDDC939FE60FA31FB9AF123B2B4D5B7A61FE +); +/*!40000 ALTER TABLE `encryption_key_canary` ENABLE KEYS */; +UNLOCK TABLES; + +-- CamelCase: issue #703 — CamelCase table and column names +CREATE TABLE `CamelCase` ( + `validSizes` varchar(12) +); + +-- countdata_template: issue #943 — bit(16) with binary default, French comment +CREATE TABLE `countdata_template` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `data` int(11) DEFAULT NULL, + `date_time` datetime DEFAULT NULL, + `gmt_offset` smallint(6) NOT NULL DEFAULT '0' COMMENT 'Offset GMT en minute', + `measurement_id` int(11) NOT NULL, + `flags` bit(16) NOT NULL DEFAULT b'0' COMMENT 'mot binaire : b1000=validé, b10000000=supprimé', + PRIMARY KEY (`id`), + UNIQUE KEY `ak_countdata_idx` (`measurement_id`, `date_time`, `gmt_offset`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='données de comptage'; + +INSERT INTO `countdata_template` (`date_time`, `measurement_id`, `flags`) VALUES + (now(), 1, b'1000'), + (now(), 2, b'10000000'); + +-- uw_defined_meaning: issue #1102 — unsigned int columns +CREATE TABLE `uw_defined_meaning` ( + `defined_meaning_id` int(8) unsigned NOT NULL, + `expression_id` int(10) NOT NULL DEFAULT '0' +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- fcm_batches: FULLTEXT index, mediumtext column +CREATE TABLE `fcm_batches` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `raw_payload` mediumtext COLLATE utf8_unicode_ci, + `success` int(10) unsigned NOT NULL DEFAULT '0', + `failed` int(10) unsigned NOT NULL DEFAULT '0', + `modified` int(10) unsigned NOT NULL DEFAULT '0', + `created_at` datetime NOT NULL, + PRIMARY KEY (`id`), + KEY `fcm_batches_created_at_index` (`created_at`), + FULLTEXT KEY `search` (`raw_payload`) +) ENGINE=InnoDB AUTO_INCREMENT=2501855 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +INSERT INTO `fcm_batches` (`raw_payload`, `created_at`) VALUES ( + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', + now() +); + +-- history: originally a separate file loaded into pgloader database +CREATE TABLE `history` ( + `hotel_id` varchar(16) NOT NULL, + `update_type` varchar(255) NOT NULL, + `code` varchar(255) DEFAULT NULL, + `affected_from` date DEFAULT NULL, + `affected_to` date DEFAULT NULL, + `submit_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `submit_ip` varchar(15) DEFAULT NULL, + `submit_user` varchar(255) DEFAULT NULL, + `id` bigint(20) UNSIGNED NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +ALTER TABLE `history` + ADD PRIMARY KEY (`id`) USING BTREE, + ADD KEY `update_type` (`update_type`), + ADD KEY `hotel_id` (`hotel_id`); + +ALTER TABLE `history` + MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT; + +-- ============================================================ +-- Former "source" database tables +-- Previously a separate database; merged here for a single-database setup. +-- Note: the multi-database scenario (loading from source + source2 separately +-- into distinct PostgreSQL schemas) is no longer represented in this seed; +-- see the report in README or git log for the trade-offs. +-- ============================================================ + +-- users: basic users table with FK-referenced orders +CREATE TABLE users ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(100) NOT NULL, + email VARCHAR(255), + age INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +CREATE INDEX idx_users_email ON users (email); + +-- Expression index: MySQL 8.0.13+. +-- MariaDB ignores MySQL-version-gated conditional comments, so this index +-- is silently skipped there (MariaDB has a different expression-index syntax). +/*!80013 CREATE INDEX idx_users_email_lower ON users ((LOWER(email))) */; + +INSERT INTO users (name, email, age) VALUES + ('Alice', 'alice@example.com', 30), + ('Bob', 'bob@example.com', 25), + ('Charlie', 'charlie@example.com', 35); + +CREATE TABLE orders ( + id INT AUTO_INCREMENT PRIMARY KEY, + user_id INT NOT NULL, + amount DECIMAL(10,2) NOT NULL, + status ENUM('pending', 'completed', 'cancelled') DEFAULT 'pending', + ordered_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +CREATE INDEX idx_orders_user_id ON orders (user_id); + +INSERT INTO orders (user_id, amount, status) VALUES + (1, 99.99, 'completed'), + (2, 49.50, 'pending'), + (1, 149.99, 'completed'); + +ALTER TABLE orders ADD CONSTRAINT fk_orders_user + FOREIGN KEY (user_id) REFERENCES users (id); + +CREATE TABLE type_mapping_test ( + id INT AUTO_INCREMENT PRIMARY KEY, + flag TINYINT(1) DEFAULT 0 COMMENT 'boolean flag: tinyint(1) maps to pg boolean', + small_val TINYINT(4) DEFAULT 0 COMMENT 'regular tinyint maps to smallint', + meta JSON DEFAULT NULL, + boundary GEOMETRY DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO type_mapping_test (flag, small_val, meta) VALUES + (1, 42, '{"key": "value"}'), + (0, 100, '{"enabled": false}'); + +CREATE TABLE flags ( + id INT AUTO_INCREMENT PRIMARY KEY, + label VARCHAR(50) NOT NULL, + is_active TINYINT(1) NOT NULL DEFAULT 1, + is_visible TINYINT(1) NOT NULL DEFAULT 0 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO flags (label, is_active, is_visible) VALUES + ('alpha', 1, 0), + ('beta', 0, 1), + ('gamma', 1, 1); + +CREATE TABLE events ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(100), + created_at DATETIME DEFAULT '0000-00-00 00:00:00', + happened DATETIME DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO events (name, created_at, happened) VALUES + ('zero-date', '0000-00-00 00:00:00', '2024-01-15 10:00:00'), + ('real-date', '2024-03-01 00:00:00', '2024-03-01 12:30:00'); + +CREATE TABLE measurements ( + id INT AUTO_INCREMENT PRIMARY KEY, + label VARCHAR(50), + reading SMALLINT UNSIGNED NOT NULL, + score TINYINT NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO measurements (label, reading, score) VALUES + ('a', 60000, 100), + ('b', 0, -50), + ('c', 32767, 127); + +-- CamelCaseTable: camelCase identifier preservation (distinct from CamelCase above) +CREATE TABLE CamelCaseTable ( + MyId INT AUTO_INCREMENT PRIMARY KEY, + MyName VARCHAR(100) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO CamelCaseTable (MyName) VALUES ('one'), ('two'); + +-- things: formerly in the separate source2 database; merged here. +-- The original purpose was to verify multi-database loading; now a simple +-- extra table to confirm the merge didn't lose the row data. +CREATE TABLE things ( + id INT AUTO_INCREMENT PRIMARY KEY, + label VARCHAR(50) +); +INSERT INTO things (label) VALUES ('foo'), ('bar'); + +-- ============================================================ +-- mysql-unit-full feature tables (#1629, #1403, #1280, #1645, +-- #1560/#1196, #1066, #1522) +-- ============================================================ + +-- #1629: datetime/timestamp precision modifier preserved (datetime(6) → timestamptz(6)) +-- #1403: CURRENT_TIMESTAMP(6) default stripped to bare keyword +CREATE TABLE type_precision ( + id INT AUTO_INCREMENT PRIMARY KEY, + ts6 DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + ts3 DATETIME(3) DEFAULT NULL, + t3 TIME(3) DEFAULT NULL, + plain_ts DATETIME DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO type_precision (ts3, t3) VALUES + ('2024-06-01 12:34:56.123', '01:02:03.456'), + ('2024-12-31 23:59:59.999', '23:59:59.999'); + +-- #1280: bit(N) DEFAULT b'0' passes through as bit literal +CREATE TABLE bit_defaults ( + id INT AUTO_INCREMENT PRIMARY KEY, + flags BIT(8) NOT NULL DEFAULT b'00000000', + single_bit BIT(1) NOT NULL DEFAULT b'0', + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO bit_defaults (flags, single_bit) VALUES + (b'10000001', b'1'), + (b'00000000', b'0'); + +-- #1645: CHECK constraints. +-- MySQL 8.0.16+ enforces these and exposes them in information_schema.CHECK_CONSTRAINTS. +-- MariaDB 10.2+ stores them but surfaces them differently — pgloader reads an empty +-- result from information_schema on MariaDB, so the expected output differs +-- between the two (see the .mariadb variant expected files). +CREATE TABLE salary_check ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(100) NOT NULL, + salary DECIMAL(10,2) NOT NULL, + age INT NOT NULL, + CONSTRAINT chk_salary_positive CHECK (salary > 0), + CONSTRAINT chk_age_range CHECK (age BETWEEN 18 AND 99) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO salary_check (name, salary, age) VALUES + ('Alice', 75000.00, 30), + ('Bob', 52000.50, 45); + +-- #1560/#1196: ON UPDATE CURRENT_TIMESTAMP → PostgreSQL BEFORE UPDATE trigger +CREATE TABLE on_update_ts ( + id INT AUTO_INCREMENT PRIMARY KEY, + payload VARCHAR(200), + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO on_update_ts (payload) VALUES ('first'), ('second'); + +-- #1066: hex-to-bytea cast function +CREATE TABLE hex_binary ( + id INT AUTO_INCREMENT PRIMARY KEY, + label VARCHAR(50), + raw_hex VARCHAR(255) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO hex_binary (label, raw_hex) VALUES + ('plain', 'DEADBEEF'), + ('prefixed', '0xCAFEBABE'), + ('empty', ''); + +-- #1522: WITHOUT TYPE cast syntax +CREATE TABLE set_column ( + id INT AUTO_INCREMENT PRIMARY KEY, + perms SET('read','write','execute') NOT NULL DEFAULT 'read' +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +INSERT INTO set_column (perms) VALUES ('read'), ('read,write'), ('read,write,execute'); + +-- ============================================================ +-- Grants +-- ============================================================ +GRANT SELECT ON pgloader_mytest.* TO 'pgloader'@'%'; +FLUSH PRIVILEGES; diff --git a/clojure/tests/mysql/my/sql/01-tables.sql b/clojure/tests/mysql/mytest/sql/01-tables.sql similarity index 53% rename from clojure/tests/mysql/my/sql/01-tables.sql rename to clojure/tests/mysql/mytest/sql/01-tables.sql index c96e6477b..d49b15463 100644 --- a/clojure/tests/mysql/my/sql/01-tables.sql +++ b/clojure/tests/mysql/mytest/sql/01-tables.sql @@ -1,5 +1,6 @@ +-- All base tables in the mytest schema, sorted alphabetically. SELECT table_name FROM information_schema.tables -WHERE table_schema = 'mysql' +WHERE table_schema = 'mytest' AND table_type = 'BASE TABLE' ORDER BY table_name; diff --git a/clojure/tests/mysql/my/sql/02-schema.sql b/clojure/tests/mysql/mytest/sql/02-schema.sql similarity index 56% rename from clojure/tests/mysql/my/sql/02-schema.sql rename to clojure/tests/mysql/mytest/sql/02-schema.sql index 0c09f5bed..7dd306810 100644 --- a/clojure/tests/mysql/my/sql/02-schema.sql +++ b/clojure/tests/mysql/mytest/sql/02-schema.sql @@ -1,5 +1,6 @@ +-- Column types for the races table (legacy "my" schema check). SELECT column_name, data_type FROM information_schema.columns -WHERE table_schema = 'mysql' +WHERE table_schema = 'mytest' AND table_name = 'races' ORDER BY ordinal_position; diff --git a/clojure/tests/mysql/my/sql/03-indexes.sql b/clojure/tests/mysql/mytest/sql/03-indexes.sql similarity index 55% rename from clojure/tests/mysql/my/sql/03-indexes.sql rename to clojure/tests/mysql/mytest/sql/03-indexes.sql index fe9fc146c..5b6e32b29 100644 --- a/clojure/tests/mysql/my/sql/03-indexes.sql +++ b/clojure/tests/mysql/mytest/sql/03-indexes.sql @@ -1,8 +1,9 @@ --- CL v3 names indexes as idx_{table_oid}_{original_name} to handle --- original names longer than PostgreSQL's 63-char limit. --- We normalize the OID to {oid} so the output is stable across container runs. +-- Non-PK indexes in the mytest schema. +-- CL v3 names indexes as idx_{table_oid}_{original_name} to handle names +-- longer than PostgreSQL's 63-char limit. +-- We normalize the OID to {oid} so output is stable across container runs. SELECT regexp_replace(indexname, 'idx_\d+_', 'idx_{oid}_') AS indexname FROM pg_indexes -WHERE schemaname = 'mysql' +WHERE schemaname = 'mytest' AND indexname NOT LIKE '%_pkey' ORDER BY regexp_replace(indexname, 'idx_\d+_', ''); diff --git a/clojure/tests/mysql/mytest/sql/04-expression-index.sql b/clojure/tests/mysql/mytest/sql/04-expression-index.sql new file mode 100644 index 000000000..807394570 --- /dev/null +++ b/clojure/tests/mysql/mytest/sql/04-expression-index.sql @@ -0,0 +1,8 @@ +-- Verify that the MySQL 8.0.13+ functional/expression index on users(LOWER(email)) +-- was created in PostgreSQL. The index definition must contain 'lower'. +-- On MariaDB this index is absent (MySQL-version-gated comment is ignored). +SELECT indexdef LIKE '%lower%' AS has_expression +FROM pg_indexes +WHERE schemaname = 'mytest' + AND tablename = 'users' + AND indexname LIKE '%email_lower%'; diff --git a/clojure/tests/mysql/mytest/sql/05-camelcase.sql b/clojure/tests/mysql/mytest/sql/05-camelcase.sql new file mode 100644 index 000000000..76d930983 --- /dev/null +++ b/clojure/tests/mysql/mytest/sql/05-camelcase.sql @@ -0,0 +1,7 @@ +-- Verify CamelCase table names and column names are preserved under quote identifiers. +SELECT count(*) FROM mytest."CamelCaseTable"; +SELECT column_name +FROM information_schema.columns +WHERE table_schema = 'mytest' + AND table_name = 'CamelCaseTable' +ORDER BY ordinal_position; diff --git a/clojure/tests/mysql/v4only/sql/02-datetime-precision.sql b/clojure/tests/mysql/mytest/sql/06-datetime-precision.sql similarity index 91% rename from clojure/tests/mysql/v4only/sql/02-datetime-precision.sql rename to clojure/tests/mysql/mytest/sql/06-datetime-precision.sql index e53a14438..06b5b5f18 100644 --- a/clojure/tests/mysql/v4only/sql/02-datetime-precision.sql +++ b/clojure/tests/mysql/mytest/sql/06-datetime-precision.sql @@ -5,6 +5,6 @@ SELECT column_name, datetime_precision, column_default FROM information_schema.columns -WHERE table_schema = 'v4' +WHERE table_schema = 'mytest' AND table_name = 'type_precision' ORDER BY ordinal_position; diff --git a/clojure/tests/mysql/v4only/sql/03-bit-defaults.sql b/clojure/tests/mysql/mytest/sql/07-bit-defaults.sql similarity index 91% rename from clojure/tests/mysql/v4only/sql/03-bit-defaults.sql rename to clojure/tests/mysql/mytest/sql/07-bit-defaults.sql index e26099800..7c1babc5d 100644 --- a/clojure/tests/mysql/v4only/sql/03-bit-defaults.sql +++ b/clojure/tests/mysql/mytest/sql/07-bit-defaults.sql @@ -4,6 +4,6 @@ SELECT column_name, data_type, column_default FROM information_schema.columns -WHERE table_schema = 'v4' +WHERE table_schema = 'mytest' AND table_name = 'bit_defaults' ORDER BY ordinal_position; diff --git a/clojure/tests/mysql/v4only/sql/04-check-constraints.sql b/clojure/tests/mysql/mytest/sql/08-check-constraints.sql similarity index 93% rename from clojure/tests/mysql/v4only/sql/04-check-constraints.sql rename to clojure/tests/mysql/mytest/sql/08-check-constraints.sql index 0c99d2fdf..f89bd6725 100644 --- a/clojure/tests/mysql/v4only/sql/04-check-constraints.sql +++ b/clojure/tests/mysql/mytest/sql/08-check-constraints.sql @@ -5,7 +5,7 @@ SELECT c.conname AS constraint_name, FROM pg_constraint c JOIN pg_class t ON t.oid = c.conrelid JOIN pg_namespace n ON n.oid = t.relnamespace -WHERE n.nspname = 'v4' +WHERE n.nspname = 'mytest' AND t.relname = 'salary_check' AND c.contype = 'c' ORDER BY c.conname; diff --git a/clojure/tests/mysql/v4only/sql/05-on-update-trigger.sql b/clojure/tests/mysql/mytest/sql/09-on-update-trigger.sql similarity index 88% rename from clojure/tests/mysql/v4only/sql/05-on-update-trigger.sql rename to clojure/tests/mysql/mytest/sql/09-on-update-trigger.sql index 68a7ca900..897598a62 100644 --- a/clojure/tests/mysql/v4only/sql/05-on-update-trigger.sql +++ b/clojure/tests/mysql/mytest/sql/09-on-update-trigger.sql @@ -3,6 +3,6 @@ SELECT trigger_name, event_manipulation, action_timing FROM information_schema.triggers -WHERE trigger_schema = 'v4' +WHERE trigger_schema = 'mytest' AND event_object_table = 'on_update_ts' ORDER BY trigger_name; diff --git a/clojure/tests/mysql/v4only/sql/06-hex-to-bytea.sql b/clojure/tests/mysql/mytest/sql/10-hex-to-bytea.sql similarity index 83% rename from clojure/tests/mysql/v4only/sql/06-hex-to-bytea.sql rename to clojure/tests/mysql/mytest/sql/10-hex-to-bytea.sql index ee2183121..5622615ff 100644 --- a/clojure/tests/mysql/v4only/sql/06-hex-to-bytea.sql +++ b/clojure/tests/mysql/mytest/sql/10-hex-to-bytea.sql @@ -1,5 +1,5 @@ -- #1066: hex-to-bytea cast — raw_hex column stored as PostgreSQL bytea \x… SELECT label, raw_hex -FROM v4.hex_binary +FROM mytest.hex_binary ORDER BY id; diff --git a/clojure/tests/mysql/v4only/sql/07-without-type.sql b/clojure/tests/mysql/mytest/sql/11-without-type.sql similarity index 85% rename from clojure/tests/mysql/v4only/sql/07-without-type.sql rename to clojure/tests/mysql/mytest/sql/11-without-type.sql index 35e04a2e2..44be269ac 100644 --- a/clojure/tests/mysql/v4only/sql/07-without-type.sql +++ b/clojure/tests/mysql/mytest/sql/11-without-type.sql @@ -2,10 +2,10 @@ -- (SET → text[]) while set-to-enum-array is applied to convert the value. SELECT column_name, data_type, udt_name FROM information_schema.columns -WHERE table_schema = 'v4' +WHERE table_schema = 'mytest' AND table_name = 'set_column' ORDER BY ordinal_position; SELECT id, perms -FROM v4.set_column +FROM mytest.set_column ORDER BY id; diff --git a/clojure/tests/mysql/source/source.load b/clojure/tests/mysql/source/source.load deleted file mode 100644 index a4a7feec1..000000000 --- a/clojure/tests/mysql/source/source.load +++ /dev/null @@ -1,8 +0,0 @@ -load database - from mysql://pgloader:pgloader@mysql:3306/source?useSSL=false - into postgresql://pgloader:pgloader@postgres:5432/target - - WITH concurrency = 1, - quote identifiers - - ALTER SCHEMA 'source' RENAME TO 'public'; diff --git a/clojure/tests/mysql/source/sql/01-expression-index.sql b/clojure/tests/mysql/source/sql/01-expression-index.sql deleted file mode 100644 index 20e6bcf32..000000000 --- a/clojure/tests/mysql/source/sql/01-expression-index.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Verify that MySQL functional/expression index was created in PostgreSQL. --- The index definition should contain 'lower' (the function expression). -SELECT indexdef LIKE '%lower%' AS has_expression -FROM pg_indexes -WHERE schemaname = 'public' - AND tablename = 'users' - AND indexname LIKE '%email_lower%'; diff --git a/clojure/tests/mysql/source/sql/02-camelcase.sql b/clojure/tests/mysql/source/sql/02-camelcase.sql deleted file mode 100644 index bf9c6a40b..000000000 --- a/clojure/tests/mysql/source/sql/02-camelcase.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Verify CamelCase table loaded with mixed-case column names preserved. -SELECT count(*) FROM public."CamelCaseTable"; -SELECT column_name -FROM information_schema.columns -WHERE table_schema = 'public' - AND table_name = 'CamelCaseTable' -ORDER BY ordinal_position; diff --git a/clojure/tests/mysql/v4only/expected/01-tables.out b/clojure/tests/mysql/v4only/expected/01-tables.out deleted file mode 100644 index f04f62d13..000000000 --- a/clojure/tests/mysql/v4only/expected/01-tables.out +++ /dev/null @@ -1,10 +0,0 @@ - table_name ----------------- - bit_defaults - hex_binary - on_update_ts - salary_check - set_column - type_precision -(6 rows) - diff --git a/clojure/tests/mysql/v4only/sql/01-tables.sql b/clojure/tests/mysql/v4only/sql/01-tables.sql deleted file mode 100644 index 90d3f1b6a..000000000 --- a/clojure/tests/mysql/v4only/sql/01-tables.sql +++ /dev/null @@ -1,6 +0,0 @@ --- All tables landed in the v4 schema -SELECT table_name -FROM information_schema.tables -WHERE table_schema = 'v4' - AND table_type = 'BASE TABLE' -ORDER BY table_name; diff --git a/clojure/tests/mysql/v4only/v4only.load b/clojure/tests/mysql/v4only/v4only.load deleted file mode 100644 index d45b45166..000000000 --- a/clojure/tests/mysql/v4only/v4only.load +++ /dev/null @@ -1,31 +0,0 @@ --- v4-only integration tests: features specific to the Clojure/JVM rewrite. --- This load file exercises behaviours not present in pgloader v3: --- #1629 datetime(N) precision preserved → timestamptz(N) --- #1403 CURRENT_TIMESTAMP(N) default stripped to keyword --- #1280 bit literal b'0' default passes through --- #1645 CHECK constraints migrated via ALTER TABLE --- #1560/#1196 ON UPDATE CURRENT_TIMESTAMP → trigger --- #1066 hex-to-bytea cast function --- #1522 WITHOUT TYPE cast syntax - -load database - from mysql://root:rootpassword@mysql:3306/pgloader_v4?useSSL=false - into postgresql://pgloader:pgloader@postgres:5432/target - - WITH create tables, - create indexes, - include drop, - quote identifiers - - ALTER SCHEMA 'pgloader_v4' RENAME TO 'v4' - - CAST - -- #1066 hex-to-bytea: load raw_hex column as PostgreSQL bytea - column hex_binary.raw_hex to bytea using hex-to-bytea, - - -- #1522 WITHOUT TYPE: preserve the SET→text[] mapping but strip - -- the surrounding braces from the comma-separated value - column set_column.perms WITHOUT TYPE using set-to-enum-array - - BEFORE LOAD DO - $$ CREATE SCHEMA IF NOT EXISTS v4; $$; From ff17e63fba5fc4197f0eccb997eb9df39ba94923 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Mon, 22 Jun 2026 21:53:52 +0200 Subject: [PATCH 3/5] fix(mysql): remove stale source target from Makefile after merge --- clojure/tests/mysql/Makefile | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/clojure/tests/mysql/Makefile b/clojure/tests/mysql/Makefile index 0ee6f35aa..029319660 100644 --- a/clojure/tests/mysql/Makefile +++ b/clojure/tests/mysql/Makefile @@ -4,7 +4,7 @@ REGRESS_FLAGS ?= .PHONY: all mytest sakila f1db source mytest-v3 -all: mytest sakila f1db source +all: mytest sakila f1db mytest: $(PGLOADER_CMD) mytest/mytest.load @@ -18,10 +18,6 @@ f1db: $(PGLOADER_CMD) f1db/f1db.load java -jar $(JAR) regress $(REGRESS_FLAGS) f1db -source: - $(PGLOADER_CMD) source/source.load - java -jar $(JAR) regress $(REGRESS_FLAGS) source - # mytest-v3: same suite against the v3 binary, compared against # .v3 variant expected files that capture deliberate v3 vs v4 differences # (serial vs identity, bit vs bit varying, trigger naming). @@ -29,7 +25,7 @@ mytest-v3: pgloader --client-min-messages notice mytest/mytest.load java -jar $(JAR) regress --variant v3 mytest -all-v3: mytest-v3 sakila-v3 f1db-v3 source-v3 +all-v3: mytest-v3 sakila-v3 f1db-v3 @: %-v3: From db709fbf8a746ca39364a33f67faf96ee84586ac Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Mon, 22 Jun 2026 22:14:06 +0200 Subject: [PATCH 4/5] ci: drop MySQL 5.7 test suite (EOL Oct 2023) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MySQL 5.7 reached end of life in October 2023. The mysql57 suite ran the same three queries as the mysql8 my-suite against the same seed schema, with one behavioral difference: int(11) display widths made v3 map INT → bigint instead of integer. That quirk is a v3 limitation, not something being fixed, so maintaining a dedicated EOL-server CI job to freeze it is more cost than value. Removes: - clojure/tests/mysql57/ (Dockerfile, docker-compose, Makefile, all suites) - CI matrix entries for mysql57 (v3) and mysql57 (v4) Also reverts a half-applied fetch-check-constraints version guard that was started to work around the now-removed suite. --- .../workflows/clojure-integration-tests.yml | 10 ---- clojure/tests/mysql57/Dockerfile | 44 ----------------- clojure/tests/mysql57/Makefile | 28 ----------- clojure/tests/mysql57/docker-compose.yml | 48 ------------------ .../tests/mysql57/f1db/expected/01-counts.out | 15 ------ clojure/tests/mysql57/f1db/f1db.load | 3 -- clojure/tests/mysql57/f1db/sql/01-counts.sql | 3 -- clojure/tests/mysql57/load-datasets.sh | 26 ---------- .../tests/mysql57/my/expected/01-tables.out | 21 -------- .../tests/mysql57/my/expected/02-schema.out | 12 ----- .../tests/mysql57/my/expected/03-indexes.out | 24 --------- clojure/tests/mysql57/my/my.load | 44 ----------------- clojure/tests/mysql57/my/sql/01-tables.sql | 5 -- clojure/tests/mysql57/my/sql/02-schema.sql | 5 -- clojure/tests/mysql57/my/sql/03-indexes.sql | 8 --- .../mysql57/sakila/expected/01-counts.out | 10 ---- .../mysql57/sakila/expected/02-matviews.out | 10 ---- .../mysql57/sakila/expected/03-schemas.out | 6 --- clojure/tests/mysql57/sakila/sakila.load | 49 ------------------- .../tests/mysql57/sakila/sql/01-counts.sql | 16 ------ .../tests/mysql57/sakila/sql/02-matviews.sql | 5 -- .../tests/mysql57/sakila/sql/03-schemas.sql | 7 --- src/sources/mysql/mysql-schema.lisp | 2 +- 23 files changed, 1 insertion(+), 400 deletions(-) delete mode 100644 clojure/tests/mysql57/Dockerfile delete mode 100644 clojure/tests/mysql57/Makefile delete mode 100644 clojure/tests/mysql57/docker-compose.yml delete mode 100644 clojure/tests/mysql57/f1db/expected/01-counts.out delete mode 100644 clojure/tests/mysql57/f1db/f1db.load delete mode 100644 clojure/tests/mysql57/f1db/sql/01-counts.sql delete mode 100644 clojure/tests/mysql57/load-datasets.sh delete mode 100644 clojure/tests/mysql57/my/expected/01-tables.out delete mode 100644 clojure/tests/mysql57/my/expected/02-schema.out delete mode 100644 clojure/tests/mysql57/my/expected/03-indexes.out delete mode 100644 clojure/tests/mysql57/my/my.load delete mode 100644 clojure/tests/mysql57/my/sql/01-tables.sql delete mode 100644 clojure/tests/mysql57/my/sql/02-schema.sql delete mode 100644 clojure/tests/mysql57/my/sql/03-indexes.sql delete mode 100644 clojure/tests/mysql57/sakila/expected/01-counts.out delete mode 100644 clojure/tests/mysql57/sakila/expected/02-matviews.out delete mode 100644 clojure/tests/mysql57/sakila/expected/03-schemas.out delete mode 100644 clojure/tests/mysql57/sakila/sakila.load delete mode 100644 clojure/tests/mysql57/sakila/sql/01-counts.sql delete mode 100644 clojure/tests/mysql57/sakila/sql/02-matviews.sql delete mode 100644 clojure/tests/mysql57/sakila/sql/03-schemas.sql diff --git a/.github/workflows/clojure-integration-tests.yml b/.github/workflows/clojure-integration-tests.yml index 71e96383f..5f34e79d7 100644 --- a/.github/workflows/clojure-integration-tests.yml +++ b/.github/workflows/clojure-integration-tests.yml @@ -236,16 +236,6 @@ jobs: make_target: mysql-v3 needs_f1db: true - # ── MySQL 5.7 (amd64 only via Rosetta emulation) ─────────────────── - - suite: mysql57 - pgloader: v4 - make_target: mysql57 - needs_f1db: true - - suite: mysql57 - pgloader: v3 - make_target: mysql57-v3 - needs_f1db: true - # ── MariaDB ──────────────────────────────────────────────────────── - suite: mariadb pgloader: v4 diff --git a/clojure/tests/mysql57/Dockerfile b/clojure/tests/mysql57/Dockerfile deleted file mode 100644 index 76c51ad59..000000000 --- a/clojure/tests/mysql57/Dockerfile +++ /dev/null @@ -1,44 +0,0 @@ -# MySQL 5.7 — the version CL pgloader was developed and tested against. -# amd64 only; runs under Rosetta on Apple Silicon. -FROM --platform=linux/amd64 mysql:5.7 - -# Install unzip (Oracle Linux 7 base) -RUN yum install -y unzip && yum clean all - -# Disable only_full_group_by — enabled by default since 5.7.5 but the sakila -# sample schema predates it (MySQL 5.0 era). CL pgloader was tested against -# MySQL 5.6 where this mode was off by default. -RUN printf '[mysqld]\nsql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\n' \ - > /etc/mysql/conf.d/sql-mode.cnf - -# === Sakila dataset === -COPY test/data/sakila-db.zip /tmp/sakila-db.zip -RUN unzip /tmp/sakila-db.zip -d /tmp/ \ - && mv /tmp/sakila-db/sakila-schema.sql /docker-entrypoint-initdb.d/sakila-schema.sql \ - && mv /tmp/sakila-db/sakila-data.sql /docker-entrypoint-initdb.d/sakila-data.sql \ - && rm -rf /tmp/sakila-db /tmp/sakila-db.zip - -# === F1DB dataset === -# Strip MySQL 8-only collation utf8mb4_0900_ai_ci — not available in MySQL 5.7 -COPY test/data/f1db.sql /tmp/f1db-src.sql -RUN sed 's/utf8mb4_0900_ai_ci/utf8mb4_general_ci/g; s/ ENCRYPTION=.N.//g' \ - /tmp/f1db-src.sql > /docker-entrypoint-initdb.d/f1db.sql \ - && rm /tmp/f1db-src.sql - -# === pgloader test schemas (from test/mysql/) === -COPY test/mysql/my.sql /docker-entrypoint-initdb.d/my.sql -COPY test/mysql/history.sql /docker-entrypoint-initdb.d/history.sql - -# === db789 materialized views schema === -COPY test/mysql/db789.sql /docker-entrypoint-initdb.d/db789.sql - -# === Init script === -COPY clojure/tests/mysql57/load-datasets.sh /docker-entrypoint-initdb.d/load-datasets.sh - -RUN chmod +x /docker-entrypoint-initdb.d/load-datasets.sh \ - && mv /docker-entrypoint-initdb.d/sakila-schema.sql /docker-entrypoint-initdb.d/sakila-schema.tmpl \ - && mv /docker-entrypoint-initdb.d/sakila-data.sql /docker-entrypoint-initdb.d/sakila-data.tmpl \ - && mv /docker-entrypoint-initdb.d/f1db.sql /docker-entrypoint-initdb.d/f1db.tmpl \ - && mv /docker-entrypoint-initdb.d/my.sql /docker-entrypoint-initdb.d/my.tmpl \ - && mv /docker-entrypoint-initdb.d/history.sql /docker-entrypoint-initdb.d/history.tmpl \ - && mv /docker-entrypoint-initdb.d/db789.sql /docker-entrypoint-initdb.d/db789.tmpl diff --git a/clojure/tests/mysql57/Makefile b/clojure/tests/mysql57/Makefile deleted file mode 100644 index 503fdaf8d..000000000 --- a/clojure/tests/mysql57/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -JAR ?= /pgloader.jar -PGLOADER_CMD ?= java -jar $(JAR) -REGRESS_FLAGS ?= - -.PHONY: all my sakila f1db - -all: my sakila f1db - -my: - $(PGLOADER_CMD) my/my.load - java -jar $(JAR) regress $(REGRESS_FLAGS) my - -sakila: - $(PGLOADER_CMD) sakila/sakila.load - java -jar $(JAR) regress $(REGRESS_FLAGS) sakila - -f1db: - $(PGLOADER_CMD) f1db/f1db.load - java -jar $(JAR) regress $(REGRESS_FLAGS) f1db - -%-v3: - $(MAKE) $* PGLOADER_CMD="pgloader --client-min-messages notice" - -%-v3-debug: - $(MAKE) $* PGLOADER_CMD="pgloader --debug --client-min-messages debug" - -update-expected-%: - java -jar $(JAR) regress --update $* diff --git a/clojure/tests/mysql57/docker-compose.yml b/clojure/tests/mysql57/docker-compose.yml deleted file mode 100644 index 20f7f8c9b..000000000 --- a/clojure/tests/mysql57/docker-compose.yml +++ /dev/null @@ -1,48 +0,0 @@ -services: - postgres: - image: postgis/postgis:16-3.4 - environment: - POSTGRES_USER: pgloader - POSTGRES_PASSWORD: pgloader - POSTGRES_DB: target - healthcheck: - test: ["CMD-SHELL", "pg_isready -U pgloader -d target"] - interval: 5s - timeout: 5s - retries: 10 - - mysql: - platform: linux/amd64 - build: - context: ../../.. - dockerfile: clojure/tests/mysql57/Dockerfile - environment: - MYSQL_ROOT_PASSWORD: rootpassword - MYSQL_USER: pgloader - MYSQL_PASSWORD: pgloader - healthcheck: - test: ["CMD-SHELL", "mysql -u root -prootpassword -e 'USE pgloader; SELECT COUNT(*) FROM races' 2>/dev/null && mysql -u root -prootpassword -e 'USE sakila; SELECT COUNT(*) FROM actor' 2>/dev/null && mysql -u root -prootpassword -e 'USE f1db; SELECT COUNT(*) FROM circuits' 2>/dev/null"] - interval: 10s - timeout: 10s - retries: 30 - - test-runner: - image: pgloader-test-runner:latest - build: - context: ../../.. - dockerfile: clojure/tests/Dockerfile - volumes: - - .:/suite - - ../../target/pgloader.jar:/pgloader.jar:ro - environment: - JAR: /pgloader.jar - PGHOST: postgres - PGPORT: "5432" - PGDATABASE: target - PGUSER: pgloader - PGPASSWORD: pgloader - depends_on: - postgres: {condition: service_healthy} - mysql: {condition: service_healthy} - profiles: [test] - command: make -C /suite diff --git a/clojure/tests/mysql57/f1db/expected/01-counts.out b/clojure/tests/mysql57/f1db/expected/01-counts.out deleted file mode 100644 index 6a59916c8..000000000 --- a/clojure/tests/mysql57/f1db/expected/01-counts.out +++ /dev/null @@ -1,15 +0,0 @@ - circuits ----------- - 77 -(1 row) - - constructors --------------- - 212 -(1 row) - - drivers ---------- - 861 -(1 row) - diff --git a/clojure/tests/mysql57/f1db/f1db.load b/clojure/tests/mysql57/f1db/f1db.load deleted file mode 100644 index 35da9cb49..000000000 --- a/clojure/tests/mysql57/f1db/f1db.load +++ /dev/null @@ -1,3 +0,0 @@ -load database - from mysql://root:rootpassword@mysql:3306/f1db?useSSL=false - into pgsql://pgloader:pgloader@postgres:5432/target; diff --git a/clojure/tests/mysql57/f1db/sql/01-counts.sql b/clojure/tests/mysql57/f1db/sql/01-counts.sql deleted file mode 100644 index d446f6db7..000000000 --- a/clojure/tests/mysql57/f1db/sql/01-counts.sql +++ /dev/null @@ -1,3 +0,0 @@ -SELECT count(*) AS circuits FROM f1db.circuits; -SELECT count(*) AS constructors FROM f1db.constructors; -SELECT count(*) AS drivers FROM f1db.drivers; diff --git a/clojure/tests/mysql57/load-datasets.sh b/clojure/tests/mysql57/load-datasets.sh deleted file mode 100644 index a83dd4ddd..000000000 --- a/clojure/tests/mysql57/load-datasets.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -set -e - -echo "=== Loading Sakila ===" -mysql -u root -p"$MYSQL_ROOT_PASSWORD" < /docker-entrypoint-initdb.d/sakila-schema.tmpl -mysql -u root -p"$MYSQL_ROOT_PASSWORD" < /docker-entrypoint-initdb.d/sakila-data.tmpl - -echo "=== Loading F1DB ===" -mysql -u root -p"$MYSQL_ROOT_PASSWORD" < /docker-entrypoint-initdb.d/f1db.tmpl - -echo "=== Loading pgloader test schemas ===" -mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "CREATE DATABASE IF NOT EXISTS pgloader" -mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "SET GLOBAL sql_mode=''" pgloader -mysql -u root -p"$MYSQL_ROOT_PASSWORD" pgloader < /docker-entrypoint-initdb.d/my.tmpl -mysql -u root -p"$MYSQL_ROOT_PASSWORD" pgloader < /docker-entrypoint-initdb.d/history.tmpl - -echo "=== Loading db789 ===" -mysql -u root -p"$MYSQL_ROOT_PASSWORD" < /docker-entrypoint-initdb.d/db789.tmpl - -echo "=== Granting pgloader access ===" -mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e " - GRANT SELECT ON pgloader.* TO 'pgloader'@'%'; - GRANT SELECT ON sakila.* TO 'pgloader'@'%'; - GRANT SELECT ON f1db.* TO 'pgloader'@'%'; - FLUSH PRIVILEGES; -" diff --git a/clojure/tests/mysql57/my/expected/01-tables.out b/clojure/tests/mysql57/my/expected/01-tables.out deleted file mode 100644 index 2aa53ce56..000000000 --- a/clojure/tests/mysql57/my/expected/01-tables.out +++ /dev/null @@ -1,21 +0,0 @@ - table_name ----------------------------------- - CamelCase - base64 - bits - countdata_template - domain_filter - empty - encryption_key_canary - fcm_batches - funny_string - geom - history - onupdate - pgloader_test_unsigned - propertydecimal - races - utilisateurs__Yvelines2013-06-28 - uw_defined_meaning -(17 rows) - diff --git a/clojure/tests/mysql57/my/expected/02-schema.out b/clojure/tests/mysql57/my/expected/02-schema.out deleted file mode 100644 index f622d1d4d..000000000 --- a/clojure/tests/mysql57/my/expected/02-schema.out +++ /dev/null @@ -1,12 +0,0 @@ - column_name | data_type --------------+------------------------ - raceId | bigint - year | bigint - round | bigint - circuitId | bigint - name | character varying - date | date - time | time without time zone - url | character varying -(8 rows) - diff --git a/clojure/tests/mysql57/my/expected/03-indexes.out b/clojure/tests/mysql57/my/expected/03-indexes.out deleted file mode 100644 index 1ccfec73b..000000000 --- a/clojure/tests/mysql57/my/expected/03-indexes.out +++ /dev/null @@ -1,24 +0,0 @@ - indexname ----------------------------------------- - idx_{oid}_PRIMARY - idx_{oid}_PRIMARY - idx_{oid}_PRIMARY - idx_{oid}_PRIMARY - idx_{oid}_PRIMARY - idx_{oid}_PRIMARY - idx_{oid}_PRIMARY - idx_{oid}_PRIMARY - idx_{oid}_PRIMARY - idx_{oid}_PRIMARY - idx_{oid}_PRIMARY - idx_{oid}_ak_countdata_idx - idx_{oid}_domain_filter - idx_{oid}_domain_filter_unq - idx_{oid}_fcm_batches_created_at_index - idx_{oid}_hotel_id - idx_{oid}_patient_id - idx_{oid}_search - idx_{oid}_update_type - idx_{oid}_url -(20 rows) - diff --git a/clojure/tests/mysql57/my/my.load b/clojure/tests/mysql57/my/my.load deleted file mode 100644 index 00f6c3232..000000000 --- a/clojure/tests/mysql57/my/my.load +++ /dev/null @@ -1,44 +0,0 @@ -load database - from mysql://root:rootpassword@mysql:3306/pgloader?useSSL=false - into postgresql://pgloader:pgloader@postgres:5432/target - - WITH concurrency = 2, - multiple readers per thread, - rows per range = 50000, - quote identifiers - - ALTER SCHEMA 'pgloader' RENAME TO 'mysql' - ALTER TABLE NAMES MATCHING ~/./ SET TABLESPACE 'pg_default' - - -- INCLUDING ONLY TABLE NAMES MATCHING 'encryption_key_canary' - - CAST column utilisateurs__Yvelines2013-06-28.sexe - to text drop not null using empty-string-to-null, - - column base64.id to uuid drop typemod, - column base64.data to jsonb using base64-decode, - - -- This is now a default casting rule for MySQL - -- type bigint when signed to bigint drop typemod, - - type decimal - when (and (= 18 precision) (= 6 scale)) - to "double precision" drop typemod, - - type smallint when unsigned to int drop typemod, - - type timestamp - when default "CURRENT_TIMESTAMP" - with extra on update current timestamp - to "timestamp with time zone" - drop default drop not null drop extra - using zero-dates-to-null, - - type timestamp with extra on update current timestamp - to "timestamp with time zone" drop extra, - - column encryption_key_canary.uuid - to uuid drop typemod using byte-vector-to-hexstring - - BEFORE LOAD DO - $$ create schema if not exists mysql; $$; diff --git a/clojure/tests/mysql57/my/sql/01-tables.sql b/clojure/tests/mysql57/my/sql/01-tables.sql deleted file mode 100644 index c96e6477b..000000000 --- a/clojure/tests/mysql57/my/sql/01-tables.sql +++ /dev/null @@ -1,5 +0,0 @@ -SELECT table_name -FROM information_schema.tables -WHERE table_schema = 'mysql' - AND table_type = 'BASE TABLE' -ORDER BY table_name; diff --git a/clojure/tests/mysql57/my/sql/02-schema.sql b/clojure/tests/mysql57/my/sql/02-schema.sql deleted file mode 100644 index 0c09f5bed..000000000 --- a/clojure/tests/mysql57/my/sql/02-schema.sql +++ /dev/null @@ -1,5 +0,0 @@ -SELECT column_name, data_type -FROM information_schema.columns -WHERE table_schema = 'mysql' - AND table_name = 'races' -ORDER BY ordinal_position; diff --git a/clojure/tests/mysql57/my/sql/03-indexes.sql b/clojure/tests/mysql57/my/sql/03-indexes.sql deleted file mode 100644 index fe9fc146c..000000000 --- a/clojure/tests/mysql57/my/sql/03-indexes.sql +++ /dev/null @@ -1,8 +0,0 @@ --- CL v3 names indexes as idx_{table_oid}_{original_name} to handle --- original names longer than PostgreSQL's 63-char limit. --- We normalize the OID to {oid} so the output is stable across container runs. -SELECT regexp_replace(indexname, 'idx_\d+_', 'idx_{oid}_') AS indexname -FROM pg_indexes -WHERE schemaname = 'mysql' - AND indexname NOT LIKE '%_pkey' -ORDER BY regexp_replace(indexname, 'idx_\d+_', ''); diff --git a/clojure/tests/mysql57/sakila/expected/01-counts.out b/clojure/tests/mysql57/sakila/expected/01-counts.out deleted file mode 100644 index cbe7fddf3..000000000 --- a/clojure/tests/mysql57/sakila/expected/01-counts.out +++ /dev/null @@ -1,10 +0,0 @@ - tables_in_pagila ------------------- - 17 -(1 row) - - tables_in_mv --------------- - 6 -(1 row) - diff --git a/clojure/tests/mysql57/sakila/expected/02-matviews.out b/clojure/tests/mysql57/sakila/expected/02-matviews.out deleted file mode 100644 index c4f7bccdb..000000000 --- a/clojure/tests/mysql57/sakila/expected/02-matviews.out +++ /dev/null @@ -1,10 +0,0 @@ - table_name ----------------------------- - customer_list - film_list - nicer_but_slower_film_list - sales_by_film_category - sales_by_store_list - staff_list -(6 rows) - diff --git a/clojure/tests/mysql57/sakila/expected/03-schemas.out b/clojure/tests/mysql57/sakila/expected/03-schemas.out deleted file mode 100644 index 86c3c7cc1..000000000 --- a/clojure/tests/mysql57/sakila/expected/03-schemas.out +++ /dev/null @@ -1,6 +0,0 @@ - schema_name -------------- - mv - pagila -(2 rows) - diff --git a/clojure/tests/mysql57/sakila/sakila.load b/clojure/tests/mysql57/sakila/sakila.load deleted file mode 100644 index c3c1d8407..000000000 --- a/clojure/tests/mysql57/sakila/sakila.load +++ /dev/null @@ -1,49 +0,0 @@ -load database - from mysql://root:rootpassword@mysql:3306/sakila?useSSL=false - into postgresql://pgloader:pgloader@postgres:5432/target - - -- WITH include drop, create tables, no truncate, - -- create indexes, reset sequences, foreign keys - - -- WITH batch rows = 10000 - - WITH on error stop, concurrency = 2, workers = 6, - prefetch rows = 25000, - multiple readers per thread, rows per range = 50000, - max parallel create index = 4-- , - -- quote identifiers - - SET PostgreSQL PARAMETERS - maintenance_work_mem to '128MB', - work_mem to '12MB', - search_path to 'sakila, public, "$user"' - - SET MySQL PARAMETERS - net_read_timeout = '120', - net_write_timeout = '120' - - CAST type date drop not null drop default using zero-dates-to-null, - type datetime to timestamp drop default drop not null using zero-dates-to-null - - -- type tinyint to boolean using tinyint-to-boolean, - -- type year to integer drop typemod -- now a default - - -- MATERIALIZE VIEWS film_list, staff_list - MATERIALIZE ALL VIEWS - - ALTER TABLE NAMES MATCHING ~/_list$/, 'sales_by_store', ~/sales_by/ - SET SCHEMA 'mv' - - ALTER TABLE NAMES MATCHING 'sales_by_store' RENAME TO 'sales_by_store_list' - ALTER TABLE NAMES MATCHING 'film' RENAME TO 'films' - ALTER TABLE NAMES MATCHING ~/./ SET (fillfactor='40') - - ALTER SCHEMA 'sakila' RENAME TO 'pagila' - - -- INCLUDING ONLY TABLE NAMES MATCHING ~/film/, 'actor' - -- EXCLUDING TABLE NAMES MATCHING ~ - - BEFORE LOAD DO - $$ create schema if not exists pagila; $$, - $$ create schema if not exists mv; $$, - $$ alter database target set search_path to pagila, mv, public; $$; diff --git a/clojure/tests/mysql57/sakila/sql/01-counts.sql b/clojure/tests/mysql57/sakila/sql/01-counts.sql deleted file mode 100644 index 3e69a2e3a..000000000 --- a/clojure/tests/mysql57/sakila/sql/01-counts.sql +++ /dev/null @@ -1,16 +0,0 @@ --- MATERIALIZE ALL VIEWS works fully on this environment. --- Two fixes were required to restore it (both in src/sources/mysql/): --- 1. enum-or-set-name deduplicates by source-def so view columns with the --- same ENUM values as a base table column reuse the existing sqltype. --- 2. only_full_group_by disabled in /etc/mysql/conf.d/sql-mode.cnf — --- the sakila schema predates MySQL 5.7.5 (which enabled it by default) --- and CL pgloader was originally tested against MySQL 5.6. -SELECT count(*) AS tables_in_pagila -FROM information_schema.tables -WHERE table_schema = 'pagila' - AND table_type = 'BASE TABLE'; - -SELECT count(*) AS tables_in_mv -FROM information_schema.tables -WHERE table_schema = 'mv' - AND table_type = 'BASE TABLE'; diff --git a/clojure/tests/mysql57/sakila/sql/02-matviews.sql b/clojure/tests/mysql57/sakila/sql/02-matviews.sql deleted file mode 100644 index b49a726b7..000000000 --- a/clojure/tests/mysql57/sakila/sql/02-matviews.sql +++ /dev/null @@ -1,5 +0,0 @@ -SELECT table_name -FROM information_schema.tables -WHERE table_schema = 'mv' - AND table_type = 'BASE TABLE' -ORDER BY table_name; diff --git a/clojure/tests/mysql57/sakila/sql/03-schemas.sql b/clojure/tests/mysql57/sakila/sql/03-schemas.sql deleted file mode 100644 index 1fabf54d8..000000000 --- a/clojure/tests/mysql57/sakila/sql/03-schemas.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Which schemas exist after the migration attempt? --- CL v3 bug: MATERIALIZE ALL VIEWS fails on film_list_rating type, --- causing a FATAL that rolls back even the base table DDL. -SELECT schema_name -FROM information_schema.schemata -WHERE schema_name IN ('pagila', 'mv') -ORDER BY schema_name; diff --git a/src/sources/mysql/mysql-schema.lisp b/src/sources/mysql/mysql-schema.lisp index a614a5da9..710815ea5 100644 --- a/src/sources/mysql/mysql-schema.lisp +++ b/src/sources/mysql/mysql-schema.lisp @@ -204,7 +204,7 @@ ;; quoting so the CHECK clause is valid SQL in PostgreSQL. (let ((pg-clause (ppcre:regex-replace-all "`([^`]+)`" check-clause "\"\\1\""))) - (add-check-constraint table constraint-name pg-clause)))))) + (add-check-constraint table constraint-name pg-clause))))))) ;;; ;;; MySQL table row count estimate From 404b1b0892f239d7d2f07c36da6fc21b18e07044 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Mon, 22 Jun 2026 22:21:58 +0200 Subject: [PATCH 5/5] fix(mysql): remove extra closing paren in fetch-check-constraints Unmatched close parenthesis caused SBCL 2.1.11 (Debian) to fail when compiling fetch-check-constraints, breaking all v3 test suites. --- src/sources/mysql/mysql-schema.lisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sources/mysql/mysql-schema.lisp b/src/sources/mysql/mysql-schema.lisp index 710815ea5..a614a5da9 100644 --- a/src/sources/mysql/mysql-schema.lisp +++ b/src/sources/mysql/mysql-schema.lisp @@ -204,7 +204,7 @@ ;; quoting so the CHECK clause is valid SQL in PostgreSQL. (let ((pg-clause (ppcre:regex-replace-all "`([^`]+)`" check-clause "\"\\1\""))) - (add-check-constraint table constraint-name pg-clause))))))) + (add-check-constraint table constraint-name pg-clause)))))) ;;; ;;; MySQL table row count estimate