Libraries
    Preparing search index...
    • Execute a MigrationDiff directly against a live database without writing a migration file. Intended for db push (dev-only schema sync).

      Foreign-key constraint drops are executed as raw ALTER TABLE … DROP CONSTRAINT statements before the main alterTable call.

      Parameters

      • knex: Knex

        A configured Knex instance or transaction.

      • diff: MigrationDiff

        The diff from diffSchema.

      • tableName: string

        The table to alter.

      Returns Promise<void>

      const dbState = await introspectDatabase(knex, 'users');
      const diff = diffSchema(UserSchema, dbState);
      if (!isDiffEmpty(diff)) await applyDiff(knex, diff, 'users');