rake-db 2.29.3 → 2.29.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1746,7 +1746,100 @@ declare const dbColumnToAst: (ctx: StructureToAstCtx, data: IntrospectedStructur
1746
1746
  declare const writeMigrationFile: (config: RakeDbConfig, version: string, name: string, migrationCode: string) => Promise<void>;
1747
1747
  declare const makeFileVersion: (ctx: RakeDbCtx, config: RakeDbConfig) => Promise<string>;
1748
1748
 
1749
+ type CreateOrDropOk = 'done' | 'already';
1750
+ /**
1751
+ * To create a database, reconfigure the connection with a power user and an existing database to connect to.
1752
+ *
1753
+ * ```ts
1754
+ * import { createDatabase } from 'orchid-orm/migrations';
1755
+ *
1756
+ * const adapter = db.$adapter.reconfigure({
1757
+ * user: 'postgres',
1758
+ * database: 'postgres',
1759
+ * });
1760
+ *
1761
+ * await createDatabase(adapter, {
1762
+ * database: 'database-to-create',
1763
+ * owner: 'username', // optional
1764
+ * });
1765
+ * ```
1766
+ */
1767
+ declare const createDatabase: (db: DbParam, { database, owner, }: {
1768
+ database: string;
1769
+ owner?: string;
1770
+ }) => Promise<CreateOrDropOk>;
1771
+ /**
1772
+ * To drop a database, reconfigure the connection with a power user and a different database to connect to.
1773
+ *
1774
+ * Ensure the connections to the database are closed before dropping, because Postgres won't be able to drop it otherwise.
1775
+ *
1776
+ * ```ts
1777
+ * import { createDatabase } from 'orchid-orm/migrations';
1778
+ *
1779
+ * const adapter = db.$adapter.reconfigure({
1780
+ * user: 'postgres',
1781
+ * database: 'postgres',
1782
+ * });
1783
+ *
1784
+ * await createDatabase(adapter, {
1785
+ * database: 'database-to-create',
1786
+ * owner: 'username', // optional
1787
+ * });
1788
+ * ```
1789
+ */
1790
+ declare const dropDatabase: (db: DbParam, { database }: {
1791
+ database: string;
1792
+ }) => Promise<CreateOrDropOk>;
1793
+ /**
1794
+ * `createSchema` uses a savepoint when it is called in a transaction to not break it if the schema already exists.
1795
+ *
1796
+ * Prepends `CREATE SCHEMA` to a given SQL.
1797
+ *
1798
+ * ```ts
1799
+ * import { createSchema } from 'orchid-orm/migrations';
1800
+ *
1801
+ * const result: 'done' | 'already' = await createSchema(db, '"schema"');
1802
+ * ```
1803
+ */
1804
+ declare const createSchema: (db: DbParam, sql: string) => Promise<'done' | 'already'>;
1805
+ /**
1806
+ * `dropSchema` uses a savepoint when it is called in a transaction to not break it if the schema does not exist.
1807
+ *
1808
+ * Prepends `DROP SCHEMA` to a given SQL.
1809
+ *
1810
+ * ```ts
1811
+ * import { dropSchema } from 'orchid-orm/migrations';
1812
+ *
1813
+ * const result: 'done' | 'already' = await dropSchema(db, '"schema"');
1814
+ * ```
1815
+ */
1816
+ declare const dropSchema: (db: DbParam, sql: string) => Promise<'done' | 'already'>;
1817
+ /**
1818
+ * `createTable` uses a savepoint when it is called in a transaction to not break it if the table already exists.
1819
+ *
1820
+ * Prepends `CREATE TABLE` to a given SQL.
1821
+ *
1822
+ * ```ts
1823
+ * import { createTable } from 'orchid-orm/migrations';
1824
+ *
1825
+ * const result: 'done' | 'already' = await createTable(db, '"table"');
1826
+ * ```
1827
+ */
1828
+ declare const createTable: (db: DbParam, sql: string) => Promise<'done' | 'already'>;
1829
+ /**
1830
+ * `dropTable` uses a savepoint when it is called in a transaction to not break it if the table does not exist.
1831
+ *
1832
+ * Prepends `DROP TABLE` to a given SQL.
1833
+ *
1834
+ * ```ts
1835
+ * import { dropTable } from 'orchid-orm/migrations';
1836
+ *
1837
+ * const result: 'done' | 'already' = await dropTable(db, '"table"');
1838
+ * ```
1839
+ */
1840
+ declare const dropTable: (db: DbParam, sql: string) => Promise<'done' | 'already'>;
1841
+
1749
1842
  declare class RakeDbError extends Error {
1750
1843
  }
1751
1844
 
1752
- export { type ChangeCallback, type DbMigration, DbStructure, type IntrospectedStructure, RakeDbAst, type RakeDbChangeFn, type RakeDbCliConfigInput, type RakeDbConfig, RakeDbError, type RakeDbFn, type SilentQueries, type StructureToAstCtx, type StructureToAstTableData, astToMigration, concatSchemaAndName, createMigrationInterface, dbColumnToAst, encodeColumnDefault, getConstraintName, getDbStructureTableData, getDbTableColumnsChecks, getExcludeName, getIndexName, getMigrationsSchemaAndTable, getSchemaAndTableFromName, incrementIntermediateCaller, instantiateDbColumn, introspectDbSchema, makeDomainsMap, makeFileVersion, makeRakeDbConfig, makeStructureToAstCtx, migrate, migrateAndClose, migrationConfigDefaults, promptSelect, rakeDbCliWithAdapter, rakeDbCommands, redo, rollback, runMigration, saveMigratedVersion, setRakeDbCliRunFn, structureToAst, tableToAst, writeMigrationFile };
1845
+ export { type ChangeCallback, type DbMigration, DbStructure, type IntrospectedStructure, RakeDbAst, type RakeDbChangeFn, type RakeDbCliConfigInput, type RakeDbConfig, RakeDbError, type RakeDbFn, type SilentQueries, type StructureToAstCtx, type StructureToAstTableData, astToMigration, concatSchemaAndName, createDatabase, createMigrationInterface, createSchema, createTable, dbColumnToAst, dropDatabase, dropSchema, dropTable, encodeColumnDefault, getConstraintName, getDbStructureTableData, getDbTableColumnsChecks, getExcludeName, getIndexName, getMigrationsSchemaAndTable, getSchemaAndTableFromName, incrementIntermediateCaller, instantiateDbColumn, introspectDbSchema, makeDomainsMap, makeFileVersion, makeRakeDbConfig, makeStructureToAstCtx, migrate, migrateAndClose, migrationConfigDefaults, promptSelect, rakeDbCliWithAdapter, rakeDbCommands, redo, rollback, runMigration, saveMigratedVersion, setRakeDbCliRunFn, structureToAst, tableToAst, writeMigrationFile };
package/dist/index.js CHANGED
@@ -246,7 +246,9 @@ const createOrDrop = async (db, sql) => {
246
246
  }
247
247
  };
248
248
  const createSchema$1 = async (db, sql) => runSqlInSavePoint(db, `CREATE SCHEMA ${sql}`, "42P06");
249
+ const dropSchema = async (db, sql) => runSqlInSavePoint(db, `DROP SCHEMA ${sql}`, "3F000");
249
250
  const createTable$1 = async (db, sql) => runSqlInSavePoint(db, `CREATE TABLE ${sql}`, "42P07");
251
+ const dropTable = async (db, sql) => runSqlInSavePoint(db, `DROP TABLE ${sql}`, "42P01");
250
252
 
251
253
  const RAKE_DB_LOCK_KEY = "8582141715823621641";
252
254
  const getFirstWordAndRest = (input) => {
@@ -6078,8 +6080,14 @@ for (const key in rakeDbAliases) {
6078
6080
  exports.RakeDbError = RakeDbError;
6079
6081
  exports.astToMigration = astToMigration;
6080
6082
  exports.concatSchemaAndName = concatSchemaAndName;
6083
+ exports.createDatabase = createDatabase;
6081
6084
  exports.createMigrationInterface = createMigrationInterface;
6085
+ exports.createSchema = createSchema$1;
6086
+ exports.createTable = createTable$1;
6082
6087
  exports.dbColumnToAst = dbColumnToAst;
6088
+ exports.dropDatabase = dropDatabase;
6089
+ exports.dropSchema = dropSchema;
6090
+ exports.dropTable = dropTable;
6083
6091
  exports.encodeColumnDefault = encodeColumnDefault;
6084
6092
  exports.getConstraintName = getConstraintName;
6085
6093
  exports.getDbStructureTableData = getDbStructureTableData;