step 2: Add UUID columns with backfill and dual-write support
- Add migration 000007: Add UUID columns to soundtrack and song with backfill - Update InsertSoundtrack and InsertSoundtrackWithExistingId to accept UUID - Update AddSong to accept UUID - Add dual-write: Go code now generates UUIDs for new records - Add uuid and pgtype imports Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -10,14 +10,6 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type IDMigrationStatus struct {
|
||||
TableName string `json:"table_name"`
|
||||
TotalRows int32 `json:"total_rows"`
|
||||
MigratedRows int32 `json:"migrated_rows"`
|
||||
Completed bool `json:"completed"`
|
||||
StartedAt *time.Time `json:"started_at"`
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
Token string `json:"token"`
|
||||
IpAddress string `json:"ip_address"`
|
||||
|
||||
@@ -27,19 +27,21 @@ func (q *Queries) AddHashToSong(ctx context.Context, arg AddHashToSongParams) er
|
||||
}
|
||||
|
||||
const addSong = `-- name: AddSong :exec
|
||||
INSERT INTO song(soundtrack_id, song_name, path, file_name, hash) VALUES ($1, $2, $3, $4, $5)
|
||||
INSERT INTO song(uuid, soundtrack_id, song_name, path, file_name, hash) VALUES ($1, $2, $3, $4, $5, $6)
|
||||
`
|
||||
|
||||
type AddSongParams struct {
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SongName string `json:"song_name"`
|
||||
Path string `json:"path"`
|
||||
FileName *string `json:"file_name"`
|
||||
Hash string `json:"hash"`
|
||||
Uuid pgtype.UUID `json:"uuid"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SongName string `json:"song_name"`
|
||||
Path string `json:"path"`
|
||||
FileName *string `json:"file_name"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
func (q *Queries) AddSong(ctx context.Context, arg AddSongParams) error {
|
||||
_, err := q.db.Exec(ctx, addSong,
|
||||
arg.Uuid,
|
||||
arg.SoundtrackID,
|
||||
arg.SongName,
|
||||
arg.Path,
|
||||
|
||||
@@ -7,6 +7,8 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const addSoundtrackPlayed = `-- name: AddSoundtrackPlayed :exec
|
||||
@@ -153,36 +155,44 @@ func (q *Queries) GetSoundtrackNameById(ctx context.Context, id int32) (string,
|
||||
}
|
||||
|
||||
const insertSoundtrack = `-- name: InsertSoundtrack :one
|
||||
INSERT INTO soundtrack (soundtrack_name, path, hash, added) VALUES ($1, $2, $3, now()) returning id
|
||||
INSERT INTO soundtrack (uuid, soundtrack_name, path, hash, added) VALUES ($1, $2, $3, $4, now()) returning id
|
||||
`
|
||||
|
||||
type InsertSoundtrackParams struct {
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
Path string `json:"path"`
|
||||
Hash string `json:"hash"`
|
||||
Uuid pgtype.UUID `json:"uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
Path string `json:"path"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertSoundtrack(ctx context.Context, arg InsertSoundtrackParams) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, insertSoundtrack, arg.SoundtrackName, arg.Path, arg.Hash)
|
||||
row := q.db.QueryRow(ctx, insertSoundtrack,
|
||||
arg.Uuid,
|
||||
arg.SoundtrackName,
|
||||
arg.Path,
|
||||
arg.Hash,
|
||||
)
|
||||
var id int32
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const insertSoundtrackWithExistingId = `-- name: InsertSoundtrackWithExistingId :exec
|
||||
INSERT INTO soundtrack (id, soundtrack_name, path, hash, added) VALUES ($1, $2, $3, $4, now())
|
||||
INSERT INTO soundtrack (id, uuid, soundtrack_name, path, hash, added) VALUES ($1, $2, $3, $4, $5, now())
|
||||
`
|
||||
|
||||
type InsertSoundtrackWithExistingIdParams struct {
|
||||
ID int32 `json:"id"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
Path string `json:"path"`
|
||||
Hash string `json:"hash"`
|
||||
ID int32 `json:"id"`
|
||||
Uuid pgtype.UUID `json:"uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
Path string `json:"path"`
|
||||
Hash string `json:"hash"`
|
||||
}
|
||||
|
||||
func (q *Queries) InsertSoundtrackWithExistingId(ctx context.Context, arg InsertSoundtrackWithExistingIdParams) error {
|
||||
_, err := q.db.Exec(ctx, insertSoundtrackWithExistingId,
|
||||
arg.ID,
|
||||
arg.Uuid,
|
||||
arg.SoundtrackName,
|
||||
arg.Path,
|
||||
arg.Hash,
|
||||
|
||||
Reference in New Issue
Block a user