| name | add-migration |
| description | Generates numbered SQL migration files for tables, indexes, and views. Use when adding or modifying database schema. |
| disable-model-invocation | true |
| user-invocable | true |
| argument-hint | <์ค๋ช
_snake_case> [ํ
์ด๋ธ๋ช
|๊ธฐ๋ฅ๋ช
] |
| allowed-tools | Read, Grep, Write, Bash(podman *) |
DB ๋ง์ด๊ทธ๋ ์ด์
์ถ๊ฐ ์ํฌํ๋ก์ฐ
$ARGUMENTS ๋ง์ด๊ทธ๋ ์ด์
์ ์์ฑํฉ๋๋ค.
1๋จ๊ณ: ๋ค์ ๋ฒํธ ๊ฒฐ์
ls migrations/ | sort | tail -1
ํ์ฌ ๋ง์ง๋ง ๋ฒํธ + 1์ ์ฌ์ฉํฉ๋๋ค.
2๋จ๊ณ: ๋ง์ด๊ทธ๋ ์ด์
ํ์ผ ์์ฑ
์์น: migrations/<๋ฒํธ>_$ARGUMENTS[0].sql
์์ฑ ๊ท์น
CREATE TABLE IF NOT EXISTS <ํ
์ด๋ธ๋ช
> (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE INDEX IF NOT EXISTS idx_<ํ
์ด๋ธ>_<์ปฌ๋ผ>
ON <ํ
์ด๋ธ> (<์ปฌ๋ผ>);
์ฒดํฌํฌ์ธํธ
3๋จ๊ณ: ์ ์ฉ ๋ฐ ๊ฒ์ฆ
# 1. ๋ง์ด๊ทธ๋ ์ด์
์ ์ฉ
podman exec -i trader-timescaledb psql -U trader -d trader -f /dev/stdin < migrations/<๋ฒํธ>_$ARGUMENTS[0].sql
# 2. ํ
์ด๋ธ ํ์ธ
podman exec trader-timescaledb psql -U trader -d trader -c "\dt <ํ
์ด๋ธ๋ช
>"
# 3. ์คํค๋ง ํ์ธ
podman exec trader-timescaledb psql -U trader -d trader -c "\d <ํ
์ด๋ธ๋ช
>"
๊ฒ์ฆ ์คํจ ์
- ์๋ฌ ๋ฉ์์ง์์ ์์ธ ํ์
(syntax error, duplicate, constraint ๋ฑ)
- ๋ง์ด๊ทธ๋ ์ด์
.sql ํ์ผ ์์
DROP TABLE IF EXISTS ํ ์ฌ์ ์ฉํ์ฌ ๊ฒ์ฆ ๋ฐ๋ณต
4๋จ๊ณ: Rust ๋ชจ๋ธ ์ฐ๋ (ํ์์)
ํด๋น ํ
์ด๋ธ์ ๋ํ Rust ๊ตฌ์กฐ์ฒด๊ฐ ํ์ํ ๊ฒฝ์ฐ:
crates/trader-core/src/domain/ ๋๋ ํด๋น crate์ ๋ชจ๋ธ ์ถ๊ฐ
sqlx::FromRow derive ์ถ๊ฐ
- Repository ํจ์ ๊ตฌํ
5๋จ๊ณ: docs ๊ฐฑ์
docs/migration_guide.md์ ์ ๋ง์ด๊ทธ๋ ์ด์
์ ๋ณด ์ถ๊ฐ.