rake-db 2.22.0 → 2.22.2
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 +38 -1
- package/dist/index.js +26 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -214,6 +214,25 @@ declare const tableChangeMethods: {
|
|
|
214
214
|
nullable(): Change;
|
|
215
215
|
nonNullable(): Change;
|
|
216
216
|
comment(comment: string | null): Change;
|
|
217
|
+
/**
|
|
218
|
+
* Rename a column:
|
|
219
|
+
*
|
|
220
|
+
* ```ts
|
|
221
|
+
* import { change } from '../dbScript';
|
|
222
|
+
*
|
|
223
|
+
* change(async (db) => {
|
|
224
|
+
* await db.changeTable('table', (t) => ({
|
|
225
|
+
* oldColumnName: t.rename('newColumnName'),
|
|
226
|
+
* }));
|
|
227
|
+
* });
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* Note that the renaming `ALTER TABLE` is executed before the rest of alterations,
|
|
231
|
+
* so if you're also adding a new constraint on this column inside the same `changeTable`,
|
|
232
|
+
* refer to it with a new name.
|
|
233
|
+
*
|
|
234
|
+
* @param name
|
|
235
|
+
*/
|
|
217
236
|
rename(name: string): RakeDbAst.ChangeTableItem.Rename;
|
|
218
237
|
primaryKey<Columns extends [string, ...string[]], Name extends string>(columns: Columns, name?: Name | undefined): {
|
|
219
238
|
tableDataItem: true;
|
|
@@ -222,7 +241,25 @@ declare const tableChangeMethods: {
|
|
|
222
241
|
};
|
|
223
242
|
unique<Columns_1 extends [string | TableData.Index.ColumnOrExpressionOptions<string>, ...(string | TableData.Index.ColumnOrExpressionOptions<string>)[]], Name_1 extends string>(columns: Columns_1, ...args: [options?: TableData.Index.UniqueOptionsArg | undefined] | [name?: Name_1 | undefined, options?: TableData.Index.UniqueOptionsArg | undefined]): {
|
|
224
243
|
tableDataItem: true;
|
|
225
|
-
columns: Columns_1 extends (string | TableData.Index.ColumnOptionsForColumn<string>)[] ? { [I in keyof Columns_1]: "column" extends keyof Columns_1[I] ? Columns_1[I][keyof Columns_1[I] & "column"] : Columns_1[I]; } : never;
|
|
244
|
+
columns: Columns_1 extends (string | TableData.Index.ColumnOptionsForColumn<string>)[] ? { [I in keyof Columns_1]: "column" extends keyof Columns_1[I] ? Columns_1[I][keyof Columns_1[I] & "column"] : Columns_1[I]; } : never; /**
|
|
245
|
+
* Rename a column:
|
|
246
|
+
*
|
|
247
|
+
* ```ts
|
|
248
|
+
* import { change } from '../dbScript';
|
|
249
|
+
*
|
|
250
|
+
* change(async (db) => {
|
|
251
|
+
* await db.changeTable('table', (t) => ({
|
|
252
|
+
* oldColumnName: t.rename('newColumnName'),
|
|
253
|
+
* }));
|
|
254
|
+
* });
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* Note that the renaming `ALTER TABLE` is executed before the rest of alterations,
|
|
258
|
+
* so if you're also adding a new constraint on this column inside the same `changeTable`,
|
|
259
|
+
* refer to it with a new name.
|
|
260
|
+
*
|
|
261
|
+
* @param name
|
|
262
|
+
*/
|
|
226
263
|
name: string extends Name_1 ? never : Name_1;
|
|
227
264
|
};
|
|
228
265
|
index(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[], ...args: [options?: TableData.Index.OptionsArg | undefined] | [name?: string | undefined, options?: TableData.Index.OptionsArg | undefined]): pqb.TableDataItem;
|
package/dist/index.js
CHANGED
|
@@ -812,6 +812,25 @@ const tableChangeMethods = __spreadProps$5(__spreadValues$7(__spreadValues$7({},
|
|
|
812
812
|
comment(comment) {
|
|
813
813
|
return { type: "change", from: { comment: null }, to: { comment } };
|
|
814
814
|
},
|
|
815
|
+
/**
|
|
816
|
+
* Rename a column:
|
|
817
|
+
*
|
|
818
|
+
* ```ts
|
|
819
|
+
* import { change } from '../dbScript';
|
|
820
|
+
*
|
|
821
|
+
* change(async (db) => {
|
|
822
|
+
* await db.changeTable('table', (t) => ({
|
|
823
|
+
* oldColumnName: t.rename('newColumnName'),
|
|
824
|
+
* }));
|
|
825
|
+
* });
|
|
826
|
+
* ```
|
|
827
|
+
*
|
|
828
|
+
* Note that the renaming `ALTER TABLE` is executed before the rest of alterations,
|
|
829
|
+
* so if you're also adding a new constraint on this column inside the same `changeTable`,
|
|
830
|
+
* refer to it with a new name.
|
|
831
|
+
*
|
|
832
|
+
* @param name
|
|
833
|
+
*/
|
|
815
834
|
rename(name) {
|
|
816
835
|
return { type: "rename", name };
|
|
817
836
|
}
|
|
@@ -1019,7 +1038,13 @@ const astToQueries = (ast, snakeCase, language) => {
|
|
|
1019
1038
|
);
|
|
1020
1039
|
const tableName = quoteWithSchema(ast);
|
|
1021
1040
|
if (renameItems.length) {
|
|
1022
|
-
queries.push(
|
|
1041
|
+
queries.push(
|
|
1042
|
+
...renameItems.map((sql) => ({
|
|
1043
|
+
text: `ALTER TABLE ${tableName}
|
|
1044
|
+
${sql}`,
|
|
1045
|
+
values
|
|
1046
|
+
}))
|
|
1047
|
+
);
|
|
1023
1048
|
}
|
|
1024
1049
|
if (alterTable.length) {
|
|
1025
1050
|
queries.push(alterTableSql(tableName, alterTable, values));
|