FluxbaseAdminMigrations
Admin Migrations manager for database migration operations Provides create, update, delete, apply, rollback, and smart sync operations
Constructors
Section titled “Constructors”new FluxbaseAdminMigrations()
Section titled “new FluxbaseAdminMigrations()”new FluxbaseAdminMigrations(
fetch):FluxbaseAdminMigrations
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
fetch | FluxbaseFetch |
Returns
Section titled “Returns”Methods
Section titled “Methods”apply()
Section titled “apply()”apply(
name,namespace):Promise<object>
Apply a specific migration
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
name | string | undefined | Migration name |
namespace | string | 'default' | Migration namespace (default: ‘default’) |
Returns
Section titled “Returns”Promise<object>
Promise resolving to { data, error } tuple with result message
| Name | Type |
|---|---|
data | null | object |
error | null | Error |
Example
Section titled “Example”const { data, error } = await client.admin.migrations.apply('001_create_users', 'myapp')if (data) { console.log(data.message) // "Migration applied successfully"}applyPending()
Section titled “applyPending()”applyPending(
namespace):Promise<object>
Apply all pending migrations in order
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
namespace | string | 'default' | Migration namespace (default: ‘default’) |
Returns
Section titled “Returns”Promise<object>
Promise resolving to { data, error } tuple with applied/failed counts
| Name | Type |
|---|---|
data | null | object |
error | null | Error |
Example
Section titled “Example”const { data, error } = await client.admin.migrations.applyPending('myapp')if (data) { console.log(`Applied: ${data.applied.length}, Failed: ${data.failed.length}`)}create()
Section titled “create()”create(
request):Promise<object>
Create a new migration
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
request | CreateMigrationRequest | Migration configuration |
Returns
Section titled “Returns”Promise<object>
Promise resolving to { data, error } tuple with created migration
| Name | Type |
|---|---|
data | null | Migration |
error | null | Error |
Example
Section titled “Example”const { data, error } = await client.admin.migrations.create({ namespace: 'myapp', name: '001_create_users', up_sql: 'CREATE TABLE app.users (id UUID PRIMARY KEY, email TEXT)', down_sql: 'DROP TABLE app.users', description: 'Create users table'})delete()
Section titled “delete()”delete(
name,namespace):Promise<object>
Delete a migration (only if status is pending)
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
name | string | undefined | Migration name |
namespace | string | 'default' | Migration namespace (default: ‘default’) |
Returns
Section titled “Returns”Promise<object>
Promise resolving to { data, error } tuple
| Name | Type |
|---|---|
data | null |
error | null | Error |
Example
Section titled “Example”const { data, error } = await client.admin.migrations.delete('001_create_users', 'myapp')get(
name,namespace):Promise<object>
Get details of a specific migration
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
name | string | undefined | Migration name |
namespace | string | 'default' | Migration namespace (default: ‘default’) |
Returns
Section titled “Returns”Promise<object>
Promise resolving to { data, error } tuple with migration details
| Name | Type |
|---|---|
data | null | Migration |
error | null | Error |
Example
Section titled “Example”const { data, error } = await client.admin.migrations.get('001_create_users', 'myapp')getExecutions()
Section titled “getExecutions()”getExecutions(
name,namespace,limit):Promise<object>
Get execution history for a migration
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
name | string | undefined | Migration name |
namespace | string | 'default' | Migration namespace (default: ‘default’) |
limit | number | 50 | Maximum number of executions to return (default: 50, max: 100) |
Returns
Section titled “Returns”Promise<object>
Promise resolving to { data, error } tuple with execution records
| Name | Type |
|---|---|
data | null | MigrationExecution[] |
error | null | Error |
Example
Section titled “Example”const { data, error } = await client.admin.migrations.getExecutions( '001_create_users', 'myapp', 10)if (data) { data.forEach(exec => { console.log(`${exec.executed_at}: ${exec.action} - ${exec.status}`) })}list()
Section titled “list()”list(
namespace,status?):Promise<object>
List migrations in a namespace
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
namespace | string | 'default' | Migration namespace (default: ‘default’) |
status? | "pending" | "failed" | "applied" | "rolled_back" | undefined | Filter by status: ‘pending’, ‘applied’, ‘failed’, ‘rolled_back’ |
Returns
Section titled “Returns”Promise<object>
Promise resolving to { data, error } tuple with migrations array
| Name | Type |
|---|---|
data | null | Migration[] |
error | null | Error |
Example
Section titled “Example”// List all migrationsconst { data, error } = await client.admin.migrations.list('myapp')
// List only pending migrationsconst { data, error } = await client.admin.migrations.list('myapp', 'pending')register()
Section titled “register()”register(
migration):object
Register a migration locally for smart sync
Call this method to register migrations in your application code. When you call sync(), only new or changed migrations will be sent to the server.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
migration | CreateMigrationRequest | Migration definition |
Returns
Section titled “Returns”object
tuple (always succeeds unless validation fails)
| Name | Type |
|---|---|
error | null | Error |
Example
Section titled “Example”// In your app initializationconst { error: err1 } = client.admin.migrations.register({ name: '001_create_users_table', namespace: 'myapp', up_sql: 'CREATE TABLE app.users (...)', down_sql: 'DROP TABLE app.users', description: 'Initial users table'})
const { error: err2 } = client.admin.migrations.register({ name: '002_add_posts_table', namespace: 'myapp', up_sql: 'CREATE TABLE app.posts (...)', down_sql: 'DROP TABLE app.posts'})
// Sync all registered migrationsawait client.admin.migrations.sync()rollback()
Section titled “rollback()”rollback(
name,namespace):Promise<object>
Rollback a specific migration
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
name | string | undefined | Migration name |
namespace | string | 'default' | Migration namespace (default: ‘default’) |
Returns
Section titled “Returns”Promise<object>
Promise resolving to { data, error } tuple with result message
| Name | Type |
|---|---|
data | null | object |
error | null | Error |
Example
Section titled “Example”const { data, error } = await client.admin.migrations.rollback('001_create_users', 'myapp')sync()
Section titled “sync()”sync(
options):Promise<object>
Smart sync all registered migrations
Automatically determines which migrations need to be created or updated by:
- Fetching existing migrations from the server
- Comparing content hashes to detect changes
- Only sending new or changed migrations
After successful sync, can optionally auto-apply new migrations and refresh the server’s schema cache.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options | Partial<SyncMigrationsOptions> | Sync options |
Returns
Section titled “Returns”Promise<object>
Promise resolving to { data, error } tuple with sync results
| Name | Type |
|---|---|
data | null | SyncMigrationsResult |
error | null | Error |
Example
Section titled “Example”// Basic sync (idempotent - safe to call on every app startup)const { data, error } = await client.admin.migrations.sync()if (data) { console.log(`Created: ${data.summary.created}, Updated: ${data.summary.updated}`)}
// Sync with auto-apply (applies new migrations automatically)const { data, error } = await client.admin.migrations.sync({ auto_apply: true})
// Dry run to preview changes without applyingconst { data, error } = await client.admin.migrations.sync({ dry_run: true})update()
Section titled “update()”update(
name,updates,namespace):Promise<object>
Update a migration (only if status is pending)
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
name | string | undefined | Migration name |
updates | UpdateMigrationRequest | undefined | Fields to update |
namespace | string | 'default' | Migration namespace (default: ‘default’) |
Returns
Section titled “Returns”Promise<object>
Promise resolving to { data, error } tuple with updated migration
| Name | Type |
|---|---|
data | null | Migration |
error | null | Error |
Example
Section titled “Example”const { data, error } = await client.admin.migrations.update( '001_create_users', { description: 'Updated description' }, 'myapp')