Skip to content

Commit b7514f7

Browse files
committed
feat: port production taskfile
porting a taskfile that is meant to be for use in production for tasks like alembic migrations or schema initialisation, the taskfile will make it into the container images
1 parent 75b9a12 commit b7514f7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Taskfile.prod.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: '3'
2+
3+
dotenv: ['.env']
4+
5+
tasks:
6+
db:alembic:
7+
desc: arbitrary alembic command in the container
8+
cmds:
9+
- |
10+
alembic -c /opt/$PROJ_NAME/alembic.ini {{.CLI_ARGS}}
11+
db:migrate:
12+
desc: migrates models to HEAD
13+
cmds:
14+
- |
15+
alembic -c /opt/$PROJ_NAME/alembic.ini upgrade head
16+
db:alembic:heads:
17+
desc: shows the HEAD SHA for alembic migrations
18+
cmds:
19+
- |
20+
alembic -c /opt/$PROJ_NAME/alembic.ini heads
21+
db:alembic:attach:
22+
desc: join the database container to alembic migrations
23+
summary: |
24+
This is useful if you have nuked your database and re-initialised
25+
the schema and want to join back to the head alembic migrations.
26+
27+
We will attempt to create the alebmic_version table and populate
28+
the version_num field with the current head value.
29+
vars:
30+
HEAD_SHA:
31+
sh: "task db:alembic:heads | sed -e 's/ (head)//g'"
32+
cmds:
33+
- |
34+
psql \
35+
-U {{.POSTGRES_USER}} \
36+
-d {{.POSTGRES_DB}} -c \" \
37+
CREATE TABLE IF NOT EXISTS alembic_version ( version_num VARCHAR ); \
38+
INSERT INTO alembic_version ( version_num ) VALUES ( '{{.HEAD_SHA}}' );\"

0 commit comments

Comments
 (0)