Fix sql statement for mysql

This commit is contained in:
kolaente 2020-06-21 23:21:21 +02:00
parent d3cf78cb8d
commit 46003efc50
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 5 additions and 4 deletions

View File

@ -45,16 +45,17 @@ ALTER TABLE ` + table + ` DROP COLUMN ` + column + `_ts;
case schemas.MYSQL:
sql = `
ALTER TABLE ` + table + ` DROP COLUMN IF EXISTS ` + column + `_ts;
ALTER TABLE ` + table + ` ADD COLUMN ` + column + `_ts DATETIME;
UPDATE ` + table + ` SET ` + column + `_ts = TIMESTAMP 'epoch' + ` + column + ` * INTERVAL '1 second';
ALTER TABLE ` + table + ` ALTER COLUMN ` + column + ` TYPE USING ` + column + `_ts;
ALTER TABLE ` + table + ` DROP COLUMN ` + column + `_ts;
ALTER TABLE ` + table + ` ADD ` + column + `_ts DATETIME null;
UPDATE ` + table + ` SET ` + column + `_ts = FROM_UNIXTIME(` + column + `);
ALTER TABLE ` + table + ` DROP COLUMN ` + column + `;
ALTER TABLE ` + table + ` CHANGE ` + column + `_ts ` + column + ` DATETIME NOT NULL;
`
case schemas.SQLITE:
// welp
default:
return fmt.Errorf("unsupported dbms: %s", tx.Dialect().URI().DBType)
}
sess := tx.NewSession()
if err := sess.Begin(); err != nil {
return err