Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Do not create create_ts, update_ts trigger in migration_history table

天舟24eab72b64b3
diff --git a/db/mysql.go b/db/mysql.go
index 4de9f78688..cddf3da73c 100644
--- a/db/mysql.go
+++ b/db/mysql.go
@@ -265,7 +265,9 @@ func (driver *MySQLDriver) ExecuteMigration(ctx context.Context, m *MigrationInf
_, err = tx.ExecContext(ctx, `
INSERT INTO bytebase.migration_history (
created_by,
+ created_ts,
updated_by,
+ updated_ts,
namespace,
sequence,
`+"`type`,"+`
@@ -274,7 +276,7 @@ func (driver *MySQLDriver) ExecuteMigration(ctx context.Context, m *MigrationInf
statement,
execution_duration
)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
+ VALUES (?, unix_timestamp(), ?, unix_timestamp(), ?, ?, ?, ?, ?, ?, ?)
`,
m.Creator,
m.Creator,
diff --git a/db/mysql_migration_schema.sql b/db/mysql_migration_schema.sql
index 4bc38a7b78..0fcbd54dc3 100644
--- a/db/mysql_migration_schema.sql
+++ b/db/mysql_migration_schema.sql
@@ -3,6 +3,8 @@
CREATE DATABASE bytebase CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_0900_ai_ci';
-- Create migration_history table
+-- Note, we don't create trigger to update created_ts and updated_ts because that may causes error:
+-- ERROR 1419 (HY000): You do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
CREATE TABLE bytebase.migration_history (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
created_by TEXT NOT NULL,
@@ -26,23 +28,4 @@ CREATE UNIQUE INDEX bytebase_idx_unique_migration_history_namespace_sequence ON
CREATE UNIQUE INDEX bytebase_idx_unique_migration_history_namespace_version ON bytebase.migration_history (namespace(256), version(256));
-CREATE INDEX bytebase_idx_migration_history_namespace_type ON bytebase.migration_history(namespace(256), `type`);
-
-CREATE TRIGGER bytebase.trigger_update_migration_history_creation_time BEFORE
-INSERT
- ON bytebase.migration_history FOR each ROW BEGIN
-SET
- new.created_ts = unix_timestamp();
-
-SET
- new.updated_ts = unix_timestamp();
-
-END;
-
-CREATE TRIGGER bytebase.trigger_update_migration_history_modification_time BEFORE
-UPDATE
- ON bytebase.migration_history FOR each ROW BEGIN
-SET
- new.updated_ts = unix_timestamp();
-
-END;
\ No newline at end of file
+CREATE INDEX bytebase_idx_migration_history_namespace_type ON bytebase.migration_history(namespace(256), `type`);
\ No newline at end of file