rake-db 2.10.23 → 2.10.25

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.js CHANGED
@@ -169,17 +169,28 @@ const setAdminCredentialsToOptions = async (options, create) => {
169
169
  }));
170
170
  };
171
171
  const createSchemaMigrations = async (db, config) => {
172
- var _a, _b;
172
+ var _a, _b, _c;
173
+ const { schema } = db;
174
+ if (schema && schema !== "public") {
175
+ try {
176
+ await db.query(`CREATE SCHEMA "${schema}"`);
177
+ (_a = config.logger) == null ? void 0 : _a.log(`Created schema ${schema}`);
178
+ } catch (err) {
179
+ if (err.code !== "42P06") {
180
+ throw err;
181
+ }
182
+ }
183
+ }
173
184
  try {
174
185
  await db.query(
175
186
  `CREATE TABLE ${quoteWithSchema({
176
187
  name: config.migrationsTable
177
188
  })} ( version TEXT NOT NULL )`
178
189
  );
179
- (_a = config.logger) == null ? void 0 : _a.log("Created versions table");
190
+ (_b = config.logger) == null ? void 0 : _b.log("Created versions table");
180
191
  } catch (err) {
181
192
  if (err.code === "42P07") {
182
- (_b = config.logger) == null ? void 0 : _b.log("Versions table exists");
193
+ (_c = config.logger) == null ? void 0 : _c.log("Versions table exists");
183
194
  } else {
184
195
  throw err;
185
196
  }
@@ -2315,7 +2326,7 @@ const execute = async (options, sql) => {
2315
2326
  }
2316
2327
  };
2317
2328
  const createOrDrop = async (options, adminOptions, config, args) => {
2318
- var _a, _b, _c, _d, _e, _f;
2329
+ var _a, _b, _c, _d;
2319
2330
  const params = getDatabaseAndUserFromOptions(options);
2320
2331
  const result = await execute(
2321
2332
  setAdapterOptions(adminOptions, { database: "postgres" }),
@@ -2353,21 +2364,6 @@ Don't use this command for database service providers, only for a local db.`;
2353
2364
  if (!args.create)
2354
2365
  return;
2355
2366
  const db = new pqb.Adapter(options);
2356
- const { schema } = db;
2357
- if (schema) {
2358
- db.schema = void 0;
2359
- try {
2360
- await db.query(`CREATE SCHEMA "${schema}"`);
2361
- (_e = config.logger) == null ? void 0 : _e.log(`Created schema ${schema}`);
2362
- } catch (err) {
2363
- if (err.code === "42P06") {
2364
- (_f = config.logger) == null ? void 0 : _f.log(`Schema ${schema} already exists`);
2365
- } else {
2366
- throw err;
2367
- }
2368
- }
2369
- db.schema = schema;
2370
- }
2371
2367
  await createSchemaMigrations(db, config);
2372
2368
  await db.close();
2373
2369
  };