hmn/src/migration/migrations/2021-03-26T033834Z_AddSessi...

46 lines
942 B
Go
Raw Normal View History

2021-03-27 21:10:11 +00:00
package migrations
import (
"context"
"time"
"git.handmade.network/hmn/hmn/src/migration/types"
2023-01-02 21:52:41 +00:00
"github.com/jackc/pgx/v5"
2021-03-27 21:10:11 +00:00
)
func init() {
registerMigration(AddSessionTable{})
}
type AddSessionTable struct{}
func (m AddSessionTable) Version() types.MigrationVersion {
return types.MigrationVersion(time.Date(2021, 3, 26, 3, 38, 34, 0, time.UTC))
}
func (m AddSessionTable) Name() string {
return "AddSessionTable"
}
func (m AddSessionTable) Description() string {
return "Adds a session table to replace the Django session table"
}
2021-04-23 04:07:44 +00:00
func (m AddSessionTable) Up(ctx context.Context, tx pgx.Tx) error {
_, err := tx.Exec(ctx, `
2021-03-27 21:10:11 +00:00
CREATE TABLE sessions (
id VARCHAR(40) PRIMARY KEY,
username VARCHAR(150) NOT NULL,
expires_at TIMESTAMP WITH TIME ZONE NOT NULL
);
`)
return err
}
2021-04-23 04:07:44 +00:00
func (m AddSessionTable) Down(ctx context.Context, tx pgx.Tx) error {
_, err := tx.Exec(ctx, `
2021-03-27 21:10:11 +00:00
DROP TABLE sessions;
`)
return err
}