You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add multi-database support to Nandi config (#139)
* Support multi-db in Config
Fix specs and paths
Update comment to use correct class
Update comment and remove unnecessary imports
Make multi database interface private
Fix database specs and config
Fix delegation
* Unify database config
* Lint, update specs and delegation
* Support multi-db in Nandi Lockfile (#142)
* Support multi-db in Nandi Lockfile
Fix bugs, lint
Clean up specs
Fix rubocop violations
* Instantiate lockfile by database
Fix rubocop violations
* Add Nandi::Lockfile.for interface for managing multiple lock files
Reduce diffs in lockfile
Remove unnecessary spec
* Add comments for lockfile .for method and default value for db_name in initialiser
* Remove global nandilock file File mocking
* Remove named argument from `Lockfile.get` method
Remove named arg from safe migration enforcer
* Refactor safe_migration_enforcer to support multi databases (#145)
* Support validating migrations for multi-db mode
* Do not re-order constants
* Refactor safe migration enforcer
* Use separate MigrationViolations class to store state
* Support compiling migrations for multiple databases (#143)
* Remove named argument from `Lockfile.get` method
* Update compile generator args
Pass file_name, database to Nandi.compile, CompiledMigration
Update compiled_migration specs
Remove unused function
Lint changes
Add compile generator spec and fix types
* Update Nandi mocking in specs
* Always cast db name to symbol
Remove unnecessary call
* Add default argument
* Add ability to create safe migrations for multiple databases (#144)
* Add multi-database support to generators
* Update usage docs and add specs
Remove update to compile spec
Update specs
* Clean up usage docs
* Add default value to generator base class
* Bump nandi to next major version
* Update readme with multi-database functionality
* Fix path require issues and standardise name handling
Fix rubocop issues
* Use alias instead of `config`
* Always return a set in safe migration enforcer
* Remove duplicate violations from enforcer
@@ -419,11 +432,11 @@ The default lock timeout for migrations. Can be overridden by way of the `set_lo
419
432
420
433
### `migration_directory` (String)
421
434
422
-
The directory for Nandi migrations. Default: `db/safe_migrations`
435
+
The directory for Nandi migrations. Default: `db/safe_migrations`.
423
436
424
437
### `output_directory` (String)
425
438
426
-
The directory for output files. Default: `db/migrate`
439
+
The directory for output files. Default: `db/migrate`.
427
440
428
441
### `renderer` (Class)
429
442
@@ -470,6 +483,142 @@ Parameters:
470
483
471
484
`klass` (Class) — The class to initialise with the arguments to the method. It should define a `template` instance method which will return a subclass of Cell::ViewModel from the Cells templating library and a `procedure` method that returns the name of the method. It may optionally define a `mixins` method, which will return an array of `Module`s to be mixed into any migration that uses this method.
472
485
486
+
## Multi-Database Support
487
+
488
+
Nandi 2.0+ supports managing migrations for multiple databases within a single Rails application.
489
+
490
+
**Note:** Single database configurations continue to work without any changes. Multi-database support is fully backward compatible.
491
+
492
+
### Configuring Multiple Databases
493
+
494
+
Instead of setting configuration values directly, register each database with its own configuration. If no values are specified, the existing defaults will be used.
495
+
496
+
**Database-specific options** (passed to `register_database`):
497
+
These options can be set individually for each database. **All are optional** - if not specified, the standard Nandi defaults are used:
498
+
499
+
-`migration_directory`: Where Nandi migrations are stored (default: `"db/safe_migrations"` for primary, `"db/<name>_safe_migrations"` for others)
500
+
-`output_directory`: Where compiled ActiveRecord migrations go (default: `"db/migrate"` for primary, `"db/<name>_migrate"` for others)
501
+
-`lockfile_name`: Name of the lockfile for this database (default: `".nandilock.yml"` for primary, `".<name>_nandilock.yml"` for others)
502
+
-`default`: Mark this database as the default when not named `:primary` (default: `false`)
503
+
-`access_exclusive_lock_timeout`: Timeout for ACCESS EXCLUSIVE locks (default: 5,000ms)
504
+
-`access_exclusive_statement_timeout`: Statement timeout for ACCESS EXCLUSIVE operations (default: 1,500ms)
505
+
-`access_exclusive_lock_timeout_limit`: Maximum allowed lock timeout (default: 5,000ms)
506
+
-`access_exclusive_statement_timeout_limit`: Maximum allowed statement timeout (default: 1,500ms)
- If you register a database named `:primary`, it automatically becomes the default per rails conventions
618
+
- Otherwise, mark a database as default with `default: true`
619
+
- Generators without `--database` option use the default database
620
+
- Single database configurations work without changes
621
+
473
622
## `.nandiignore`
474
623
475
624
To protect people from writing unsafe migrations, we provide a script [`nandi-enforce`](https://github.com/gocardless/nandi/blob/master/exe/nandi-enforce) that ensures all migrations in the specified directories are safe migrations generated by Nandi.
0 commit comments