fix order status length

This commit is contained in:
narumi 2023-11-23 14:53:22 +08:00
parent 75b8be5e17
commit c30dd24550
4 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,11 @@
-- +up
-- +begin
ALTER TABLE `orders`
CHANGE `status` `status` varchar(20) NOT NULL;
-- +end
-- +down
-- +begin
SELECT 1;
-- +end

View File

@ -0,0 +1,12 @@
-- +up
-- +begin
-- We can not change column type in sqlite
-- However, SQLite does not enforce the length of a VARCHAR, i.e VARCHAR(8) == VARCHAR(20) == TEXT
SELECT 1;
-- +end
-- +down
-- +begin
SELECT 1;
-- +end

View File

@ -0,0 +1,34 @@
package mysql
import (
"context"
"github.com/c9s/rockhopper"
)
func init() {
AddMigration(upFixOrderStatusLength, downFixOrderStatusLength)
}
func upFixOrderStatusLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "ALTER TABLE `orders`\n CHANGE `status` `status` varchar(20) NOT NULL;")
if err != nil {
return err
}
return err
}
func downFixOrderStatusLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}

View File

@ -0,0 +1,34 @@
package sqlite3
import (
"context"
"github.com/c9s/rockhopper"
)
func init() {
AddMigration(upFixOrderStatusLength, downFixOrderStatusLength)
}
func upFixOrderStatusLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is applied.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}
func downFixOrderStatusLength(ctx context.Context, tx rockhopper.SQLExecutor) (err error) {
// This code is executed when the migration is rolled back.
_, err = tx.ExecContext(ctx, "SELECT 1;")
if err != nil {
return err
}
return err
}