Skip to content

Commit d1c444b

Browse files
authored
Merge pull request #164 from refactor-group/add_to_migration_readme
Add to migration readme
2 parents bcacfcd + 0f77578 commit d1c444b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

migration/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,39 @@ Before running migrations, ensure you have a proper environment configuration:
3535
export DATABASE_URL=postgres://refactor:password@localhost:5432/refactor_platform
3636
```
3737

38+
### Manual Schema Creation (Production)
39+
40+
For production environments the `refactor_platform` schema is **not** created automatically by SeaORM migrations.
41+
Create it once in your production database before running any migrations:
42+
43+
```sql
44+
CREATE SCHEMA IF NOT EXISTS refactor_platform;
45+
```
46+
47+
After the schema exists, run the normal migration commands (all examples below continue to use `-s refactor_platform`).
48+
49+
### Schema Privileges (Production)
50+
51+
After the schema exists, ensure the `refactor` role (used in the `DATABASE_URL`) has the proper rights; otherwise the migrator will error with `permission denied for table seaql_migrations`.
52+
53+
```sql
54+
-- Allow the role to create and use objects in the schema
55+
GRANT USAGE, CREATE ON SCHEMA refactor_platform TO refactor;
56+
57+
-- Transfer ownership of the SeaORM migrations tracking table (required if it was created by another role such as `doadmin`)
58+
ALTER TABLE refactor_platform.seaql_migrations OWNER TO refactor;
59+
60+
-- Grant DML privileges on all existing tables
61+
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA refactor_platform TO refactor;
62+
63+
-- Ensure future tables inherit these privileges
64+
ALTER DEFAULT PRIVILEGES IN SCHEMA refactor_platform
65+
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO refactor;
66+
67+
-- Ensure the application role searches the refactor_platform schema first
68+
ALTER ROLE refactor SET search_path = refactor_platform, public;
69+
```
70+
3871
## Running Migrations
3972

4073
### Important: Schema Specification

0 commit comments

Comments
 (0)