-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.flow
More file actions
114 lines (108 loc) · 3.32 KB
/
database.flow
File metadata and controls
114 lines (108 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# yaml-language-server: $schema=https://flowexec.io/schemas/flowfile_schema.json
namespace: db
description: |
Database lifecycle management for a local SQLite database. All executables
target the same `db` resource name with different verbs — showing how flow
organizes the full lifecycle of a single resource: migrate, check, inspect,
backup, rollback, and clean.
tags:
- setup
- database
executables:
- verb: migrate
name: db
description: Apply all pending SQL migration files from the migrations/ directory.
exec:
params:
- envKey: DB_PATH
text: .data/app.db
cmd: |
mkdir -p "$(dirname "${DB_PATH}")"
for f in $(find migrations -name "*.sql" 2>/dev/null | sort); do
echo "Applying ${f}..."
sqlite3 "${DB_PATH}" < "${f}"
done
echo "✓ Migrations applied to ${DB_PATH}"
- verb: check
name: db
description: Show the current schema version and list all tables.
exec:
params:
- envKey: DB_PATH
text: .data/app.db
cmd: |
if [ ! -f "${DB_PATH}" ]; then
echo "Database not found at ${DB_PATH} — run: flow migrate db"
exit 1
fi
echo "=== Tables in ${DB_PATH} ==="
sqlite3 "${DB_PATH}" ".tables"
echo ""
echo "=== Schema ==="
sqlite3 "${DB_PATH}" ".schema"
- verb: inspect
name: db
description: Open an interactive SQLite shell for the local database.
exec:
logMode: text
params:
- envKey: DB_PATH
text: .data/app.db
cmd: |
if [ ! -f "${DB_PATH}" ]; then
echo "Database not found at ${DB_PATH} — run: flow migrate db"
exit 1
fi
echo "Opening ${DB_PATH} (type .quit to exit)"
sqlite3 "${DB_PATH}"
- verb: backup
name: db
description: Copy the database to a timestamped file in .data/backups/.
exec:
params:
- envKey: DB_PATH
text: .data/app.db
cmd: |
if [ ! -f "${DB_PATH}" ]; then
echo "Database not found at ${DB_PATH}"
exit 1
fi
BACKUP=".data/backups/app-$(date +%Y%m%d-%H%M%S).db"
mkdir -p .data/backups
cp "${DB_PATH}" "${BACKUP}"
echo "✓ Backed up to ${BACKUP}"
echo ""
echo "Recent backups:"
ls -lh .data/backups/ | tail -5
- verb: rollback
name: db
description: |
Drop all tables and re-apply migrations from scratch. Useful during
development — destructive in production.
params:
- envKey: DB_PATH
text: .data/app.db
serial:
failFast: true
execs:
- cmd: |
echo "=== Dropping all tables ==="
sqlite3 "${DB_PATH}" "SELECT 'DROP TABLE IF EXISTS ' || name || ';' FROM sqlite_master WHERE type='table';" \
| sqlite3 "${DB_PATH}"
echo "✓ Tables dropped"
reviewRequired: true
- ref: "migrate flow-examples/db:db"
- verb: clean
name: db
description: Delete the local database file entirely.
exec:
params:
- envKey: DB_PATH
text: .data/app.db
cmd: |
if [ ! -f "${DB_PATH}" ]; then
echo "Nothing to clean"
exit 0
fi
rm -f "${DB_PATH}" "${DB_PATH}-shm" "${DB_PATH}-wal"
echo "✓ Deleted ${DB_PATH}"