feat: implement battle replay module with database migrations, repository, and CRUD service endpoints
All checks were successful
Build and Release / release (push) Successful in 1m32s
All checks were successful
Build and Release / release (push) Successful in 1m32s
This commit is contained in:
1
db/migrations/000017_battle_replays.down.sql
Normal file
1
db/migrations/000017_battle_replays.down.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS battle_replays;
|
||||
28
db/migrations/000017_battle_replays.up.sql
Normal file
28
db/migrations/000017_battle_replays.up.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
CREATE TABLE IF NOT EXISTS battle_replays (
|
||||
id UUID PRIMARY KEY DEFAULT uuidv7(),
|
||||
geometry_id UUID NOT NULL REFERENCES geometries(id) ON DELETE CASCADE,
|
||||
project_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
|
||||
target_geometry_ids JSONB NOT NULL DEFAULT '[]'::jsonb,
|
||||
detail JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||
is_deleted BOOLEAN NOT NULL DEFAULT false,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX idx_battle_replays_geometry_id ON battle_replays(geometry_id)
|
||||
WHERE is_deleted = false;
|
||||
|
||||
CREATE INDEX idx_battle_replays_project_id ON battle_replays(project_id)
|
||||
WHERE is_deleted = false;
|
||||
|
||||
CREATE INDEX idx_battle_replays_target_geometry_ids ON battle_replays USING GIN (target_geometry_ids)
|
||||
WHERE is_deleted = false;
|
||||
|
||||
CREATE INDEX idx_battle_replays_updated_at ON battle_replays(updated_at DESC)
|
||||
WHERE is_deleted = false;
|
||||
|
||||
DROP TRIGGER IF EXISTS trigger_battle_replays_updated_at ON battle_replays;
|
||||
CREATE TRIGGER trigger_battle_replays_updated_at
|
||||
BEFORE UPDATE ON battle_replays
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_updated_at();
|
||||
49
db/query/battle_replay.sql
Normal file
49
db/query/battle_replay.sql
Normal file
@@ -0,0 +1,49 @@
|
||||
-- name: CreateBattleReplay :one
|
||||
INSERT INTO battle_replays (
|
||||
id, geometry_id, project_id, target_geometry_ids, detail
|
||||
) VALUES (
|
||||
COALESCE(sqlc.narg('id')::uuid, uuidv7()), $1, $2, $3, $4
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetBattleReplayById :one
|
||||
SELECT *
|
||||
FROM battle_replays
|
||||
WHERE id = $1 AND is_deleted = false;
|
||||
|
||||
-- name: GetBattleReplaysByIDs :many
|
||||
SELECT * FROM battle_replays WHERE id = ANY($1::uuid[]) AND is_deleted = false;
|
||||
|
||||
-- name: GetBattleReplaysByGeometryId :many
|
||||
SELECT *
|
||||
FROM battle_replays
|
||||
WHERE geometry_id = $1 AND is_deleted = false;
|
||||
|
||||
-- name: GetBattleReplaysByGeometryIDs :many
|
||||
SELECT *
|
||||
FROM battle_replays
|
||||
WHERE geometry_id = ANY($1::uuid[]) AND is_deleted = false;
|
||||
|
||||
-- name: GetBattleReplaysByProjectId :many
|
||||
SELECT *
|
||||
FROM battle_replays
|
||||
WHERE project_id = $1 AND is_deleted = false;
|
||||
|
||||
-- name: UpdateBattleReplay :one
|
||||
UPDATE battle_replays
|
||||
SET
|
||||
geometry_id = COALESCE(sqlc.narg('geometry_id'), geometry_id),
|
||||
target_geometry_ids = COALESCE(sqlc.narg('target_geometry_ids'), target_geometry_ids),
|
||||
detail = COALESCE(sqlc.narg('detail'), detail)
|
||||
WHERE id = sqlc.arg('id') AND is_deleted = false
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteBattleReplay :exec
|
||||
UPDATE battle_replays
|
||||
SET is_deleted = true
|
||||
WHERE id = $1;
|
||||
|
||||
-- name: DeleteBattleReplaysByIDs :exec
|
||||
UPDATE battle_replays
|
||||
SET is_deleted = true
|
||||
WHERE id = ANY($1::uuid[]);
|
||||
@@ -243,3 +243,14 @@ CREATE TABLE IF NOT EXISTS chatbot_histories (
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS battle_replays (
|
||||
id UUID PRIMARY KEY DEFAULT uuidv7(),
|
||||
geometry_id UUID NOT NULL REFERENCES geometries(id) ON DELETE CASCADE,
|
||||
project_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
|
||||
target_geometry_ids JSONB NOT NULL DEFAULT '[]'::jsonb,
|
||||
detail JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||
is_deleted BOOLEAN NOT NULL DEFAULT false,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now()
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user