49 lines
1.2 KiB
Markdown
49 lines
1.2 KiB
Markdown
# Bootstrap Scripts
|
|
|
|
This directory contains data initialization scripts executed on empty databases.
|
|
|
|
## File Naming
|
|
|
|
Files are named with alphabetic prefixes for execution order:
|
|
- `01-init-roles.sql`
|
|
- `02-seed-config.py`
|
|
- `03-reference-data.sql`
|
|
|
|
Files are executed **alphabetically** (not numerically parsed).
|
|
|
|
## Execution Context
|
|
|
|
Bootstrap scripts run:
|
|
- **Development**: Each `patch apply` (allows iteration on bootstrap)
|
|
- **Production**: Initial `clone` only (one-time setup)
|
|
|
|
For production data changes, use **patches** (not bootstrap).
|
|
|
|
## Python Files
|
|
|
|
Python files can define a `run(model)` function to share the database connection:
|
|
|
|
```python
|
|
def run(model):
|
|
# model is the halfORM Model instance with active connection
|
|
MyModel = model.get_relation_class('schema.table')
|
|
MyModel(field='value').ho_insert()
|
|
```
|
|
|
|
Without `run(model)`, the file executes as a subprocess (must handle own connection).
|
|
|
|
## SQL Files
|
|
|
|
SQL files can use any SQL commands:
|
|
|
|
```sql
|
|
-- Initialize roles
|
|
INSERT INTO public.roles (name) VALUES ('admin'), ('user');
|
|
```
|
|
|
|
## Notes
|
|
|
|
- No tracking mechanism (files execute on every restore)
|
|
- Not idempotent (assumes empty database)
|
|
- Maintained manually by developers
|