|
| 1 | +# Database Migration Guide for Keyper Implementations |
| 2 | + |
| 3 | +This guide explains how to create and manage database migrations for any keyper |
| 4 | +implementation in the Rolling Shutter project. |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +Database migrations are automatically executed when running the `initdb` command |
| 9 | +for all keyper implementations. This ensures that each keyper's database schema |
| 10 | +is properly initialized and updated to the latest version. |
| 11 | + |
| 12 | +## Migration Requirements |
| 13 | + |
| 14 | +All migrations must adhere to the following prerequisites: |
| 15 | + |
| 16 | +### 1. File Location |
| 17 | + |
| 18 | +Migrations must be stored in the following directory structure: |
| 19 | + |
| 20 | +``` |
| 21 | +keyperimpl/{keyper_name}/database/sql/migrations/ |
| 22 | +``` |
| 23 | + |
| 24 | +Where `{keyper_name}` represents the specific keyper implementation (e.g., |
| 25 | +`gnosis`, `optimism`, `shutterservice`, etc.). |
| 26 | + |
| 27 | +### 2. File Format and Naming Convention |
| 28 | + |
| 29 | +- **File Format**: All migrations must be written in SQL |
| 30 | +- **Naming Convention**: Files must follow a strict versioning pattern: |
| 31 | + ``` |
| 32 | + V{version_number}_{migration_description}.sql |
| 33 | + ``` |
| 34 | + |
| 35 | +#### Examples: |
| 36 | + |
| 37 | +- `V2_validatorRegistrations.sql` |
| 38 | +- `V3_addUserTable.sql` |
| 39 | +- `V4_updateIndexes.sql` |
| 40 | + |
| 41 | +#### Version Number Rules: |
| 42 | + |
| 43 | +- **Minimum Version**: The lowest allowed version number is **2** |
| 44 | +- **Version 1**: Represents the initial database schema (automatically created) |
| 45 | +- **Sequential Ordering**: All subsequent migrations must have version numbers |
| 46 | + greater than any previously defined migration |
| 47 | + |
| 48 | +### 3. Version Tracking |
| 49 | + |
| 50 | +- Migration version records are maintained in the `meta_inf` table for each |
| 51 | + keyper |
| 52 | +- This tracking system ensures that only new migrations are executed when the |
| 53 | + `initdb` command is run again |
| 54 | +- The system automatically detects which migrations have already been applied |
| 55 | + |
| 56 | +## Important Limitations |
| 57 | + |
| 58 | +**No Rollback Support**: The migration system does not support rolling back to |
| 59 | +previous versions. Once a migration is applied, it cannot be undone through the |
| 60 | +automated migration system. |
0 commit comments