-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphased-seed.yaml
More file actions
71 lines (67 loc) · 1.98 KB
/
phased-seed.yaml
File metadata and controls
71 lines (67 loc) · 1.98 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
# Example: Multi-phase PostgreSQL seeding with MiniJinja
#
# This seed spec demonstrates:
# - MiniJinja templating with environment variables
# - Phase-based execution with ordering
# - Schema creation with create_if_missing
# - Waiting for database objects before seeding
# - Cross-table references across phases
#
# Usage:
# export DATABASE_URL=postgres://user:pass@localhost:5432/mydb
# export APP_SCHEMA=app_data
# initium seed --spec examples/seed/phased-seed.yaml
database:
driver: postgres
url_env: DATABASE_URL
phases:
# Phase 1: Create the schema if it doesn't exist
- name: create_schema
order: 1
schema: { { env.APP_SCHEMA | default("app_data") } }
create_if_missing: true
# Phase 2: Wait for tables to exist, then seed
- name: seed_departments
order: 2
timeout: 60s
wait_for:
- type: table
name: departments
- type: table
name: employees
seed_sets:
- name: departments
tables:
- table: departments
order: 1
auto_id:
column: id
unique_key: [name]
rows:
- _ref: dept_eng
name: Engineering
- _ref: dept_sales
name: Sales
- _ref: dept_ops
name: Operations
# Phase 3: Seed employees referencing departments from phase 2
- name: seed_employees
order: 3
seed_sets:
- name: employees
tables:
- table: employees
unique_key: [email]
rows:
- name: Alice
email: alice@example.com
department_id: "@ref:dept_eng.id"
- name: Bob
email: bob@example.com
department_id: "@ref:dept_eng.id"
- name: Carol
email: carol@example.com
department_id: "@ref:dept_sales.id"
- name: Dave
email: dave@example.com
department_id: "@ref:dept_ops.id"