rake-db 2.27.6 → 2.27.7

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.mjs CHANGED
@@ -418,7 +418,7 @@ const getIndexOrExcludeMainOptions = (tableName, item, getName, snakeCase) => {
418
418
  return {
419
419
  columns,
420
420
  include,
421
- name: item.name || getName(tableName, columns)
421
+ name: item.options?.name || getName(tableName, columns)
422
422
  };
423
423
  };
424
424
  const commentsToQuery = (schemaTable, comments) => {
@@ -1510,20 +1510,20 @@ class Migration {
1510
1510
  *
1511
1511
  * @param tableName - name of the table to add the index for
1512
1512
  * @param columns - indexed columns
1513
- * @param args - index options, or an index name and then options
1513
+ * @param args - index options
1514
1514
  */
1515
1515
  addIndex(tableName, columns, ...args) {
1516
- return addIndex(this, this.up, tableName, columns, args);
1516
+ return addIndex(this, this.up, tableName, columns, ...args);
1517
1517
  }
1518
1518
  /**
1519
1519
  * Drop the schema, create it on rollback. See {@link addIndex}.
1520
1520
  *
1521
1521
  * @param tableName - name of the table to add the index for
1522
1522
  * @param columns - indexed columns
1523
- * @param args - index options, or an index name and then options
1523
+ * @param args - index options
1524
1524
  */
1525
1525
  dropIndex(tableName, columns, ...args) {
1526
- return addIndex(this, !this.up, tableName, columns, args);
1526
+ return addIndex(this, !this.up, tableName, columns, ...args);
1527
1527
  }
1528
1528
  /**
1529
1529
  * Rename index:
@@ -2248,7 +2248,7 @@ const addColumn = (migration, up, tableName, columnName, fn) => {
2248
2248
  [columnName]: t.add(fn(t))
2249
2249
  }));
2250
2250
  };
2251
- const addIndex = (migration, up, tableName, columns, args) => {
2251
+ const addIndex = (migration, up, tableName, columns, ...args) => {
2252
2252
  return changeTable(migration, up, tableName, {}, (t) => ({
2253
2253
  ...t.add(t.index(columns, ...args))
2254
2254
  }));
@@ -4258,11 +4258,7 @@ const tableToAst = (ctx, data, table, action, domains) => {
4258
4258
  const indexesOrExcludesToAst = (tableName, tableData, key) => {
4259
4259
  return tableData[key].reduce((acc, item) => {
4260
4260
  if (item.columns.length > 1 || item.columns.some((it) => "expression" in it)) {
4261
- const { name, ...options } = makeIndexOrExcludeOptions(
4262
- tableName,
4263
- item,
4264
- key
4265
- );
4261
+ const options = makeIndexOrExcludeOptions(tableName, item, key);
4266
4262
  acc.push({
4267
4263
  columns: item.columns.map((it, i) => ({
4268
4264
  with: "exclude" in item && item.exclude ? item.exclude[i] : void 0,
@@ -4274,8 +4270,7 @@ const indexesOrExcludesToAst = (tableName, tableData, key) => {
4274
4270
  options: {
4275
4271
  ...options,
4276
4272
  include: item.include?.map(toCamelCase)
4277
- },
4278
- name
4273
+ }
4279
4274
  });
4280
4275
  }
4281
4276
  return acc;
@@ -4442,12 +4437,12 @@ const collectColumnIndexesOrExcludes = (dbColumn, column, tableName, tableData,
4442
4437
  ((_a = column.data)[key] ?? (_a[key] = [])).push({
4443
4438
  with: "exclude" in item && item.exclude ? item.exclude[0] : void 0,
4444
4439
  options: {
4440
+ name,
4445
4441
  collate: columnOptions.collate,
4446
4442
  opclass: columnOptions.opclass,
4447
4443
  order: columnOptions.order,
4448
4444
  ...itemOptions
4449
- },
4450
- name
4445
+ }
4451
4446
  });
4452
4447
  }
4453
4448
  };
@@ -4727,7 +4722,7 @@ const pushIndexOrExcludeKeys = (change, keys, schema, table, name, key) => {
4727
4722
  const getName = key === "indexes" ? getIndexName : getExcludeName;
4728
4723
  for (const x of items) {
4729
4724
  keys.push(
4730
- x.name ? `${schema}.${x.name}` : getName(table, [{ column: change.column?.data.name ?? name }])
4725
+ x.options.name ? `${schema}.${x.options.name}` : getName(table, [{ column: change.column?.data.name ?? name }])
4731
4726
  );
4732
4727
  }
4733
4728
  }
@@ -4737,7 +4732,9 @@ const pushIndexesOrExcludesKeys = (keys, schema, table, data, key) => {
4737
4732
  if (arr) {
4738
4733
  const getName = key === "indexes" ? getIndexName : getExcludeName;
4739
4734
  for (const x of arr) {
4740
- keys.push(x.name ? `${schema}.${x.name}` : getName(table, x.columns));
4735
+ keys.push(
4736
+ x.options.name ? `${schema}.${x.options.name}` : getName(table, x.columns)
4737
+ );
4741
4738
  }
4742
4739
  }
4743
4740
  };