@@ -120,6 +120,25 @@ func migrateDropLegacyPostTables(ctx context.Context, exec execContext) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func migratePostImages(ctx context.Context, exec execContext) error {
|
||||
if _, err := exec.ExecContext(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS post_images (
|
||||
id TEXT PRIMARY KEY,
|
||||
post_id TEXT NOT NULL REFERENCES posts(id) ON DELETE CASCADE,
|
||||
object_key TEXT NOT NULL UNIQUE,
|
||||
public_url TEXT NOT NULL,
|
||||
description TEXT NOT NULL DEFAULT '' CHECK (char_length(description) <= 500),
|
||||
position SMALLINT NOT NULL CHECK (position BETWEEN 0 AND 3),
|
||||
width INTEGER NOT NULL CHECK (width > 0),
|
||||
height INTEGER NOT NULL CHECK (height > 0),
|
||||
created_at TEXT NOT NULL,
|
||||
UNIQUE (post_id, position)
|
||||
)`); err != nil {
|
||||
return fmt.Errorf("create post images: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func migratePostDate(ctx context.Context, exec execContext) error {
|
||||
steps := []struct {
|
||||
name string
|
||||
@@ -311,6 +330,7 @@ CREATE TABLE IF NOT EXISTS schema_migrations (
|
||||
{"007_post_state", migratePostState},
|
||||
{"008_post_author_index", migratePostAuthorIndex},
|
||||
{"009_drop_legacy_post_tables", migrateDropLegacyPostTables},
|
||||
{"010_post_images", migratePostImages},
|
||||
}
|
||||
for _, m := range migrations {
|
||||
if applied[m.version] {
|
||||
|
||||
Reference in New Issue
Block a user