Merge pull request #1431 from c9s/narumi/fix-order-status-length

FIX: fix order status length
This commit is contained in:
c9s 2023-11-30 14:02:29 +08:00 committed by GitHub
commit 92b6ee0264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
}