rake-db 2.1.4 → 2.1.6
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/.env.local +1 -1
- package/CHANGELOG.md +15 -0
- package/db.ts +10 -6
- package/dist/index.d.ts +11 -6
- package/dist/index.esm.js +7 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/migrations/20221105202843_createUniqueTable.ts +1 -0
- package/package.json +11 -10
- package/src/migration/changeTable.ts +2 -2
- package/src/migration/createTable.ts +7 -1
- package/src/migration/migration.ts +12 -4
package/.env.local
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
DATABASE_URL=postgres://postgres:@localhost:5432/porm
|
|
2
|
-
DATABASE_URL_TEST=postgres://postgres:@localhost:5432/porm_test
|
|
2
|
+
#DATABASE_URL_TEST=postgres://postgres:@localhost:5432/porm_test
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# rake-db
|
|
2
2
|
|
|
3
|
+
## 2.1.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add required min and max parameters to text column
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- pqb@0.7.3
|
|
10
|
+
|
|
11
|
+
## 2.1.5
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [9b8b3d5]
|
|
16
|
+
- pqb@0.7.2
|
|
17
|
+
|
|
3
18
|
## 2.1.4
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/db.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { config } from 'dotenv';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { rakeDb } from './src/rakeDb';
|
|
4
|
+
import { AdapterOptions } from 'pqb';
|
|
4
5
|
|
|
5
6
|
config({ path: path.resolve(process.cwd(), '.env.local') });
|
|
6
7
|
config();
|
|
7
8
|
|
|
9
|
+
const options: AdapterOptions[] = [];
|
|
10
|
+
|
|
8
11
|
const connectionString = process.env.DATABASE_URL;
|
|
9
12
|
if (!connectionString) {
|
|
10
13
|
throw new Error('DATABASE_URL is missing in .env');
|
|
11
14
|
}
|
|
12
15
|
|
|
16
|
+
options.push({ connectionString });
|
|
17
|
+
|
|
13
18
|
const connectionStringTest = process.env.DATABASE_URL_TEST;
|
|
14
|
-
if (
|
|
15
|
-
|
|
19
|
+
if (connectionStringTest) {
|
|
20
|
+
options.push({ connectionString: connectionStringTest });
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
rakeDb(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
);
|
|
23
|
+
rakeDb(options, {
|
|
24
|
+
migrationsPath: path.resolve(process.cwd(), 'migrations'),
|
|
25
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as pqb from 'pqb';
|
|
2
|
-
import { NoPrimaryKeyOption, QueryLogOptions, MaybeArray, AdapterOptions,
|
|
2
|
+
import { NoPrimaryKeyOption, QueryLogOptions, MaybeArray, AdapterOptions, EmptyObject, RawExpression, ColumnType, ForeignKey, SingleColumnIndexOptions, ColumnTypes, raw, ColumnsShape, IndexColumnOptions, IndexOptions, TransactionAdapter, QueryLogObject, QueryResultRow, QueryInput, TypeParsers, QueryResult, QueryArraysResult, ForeignKeyOptions, TextColumn } from 'pqb';
|
|
3
3
|
|
|
4
4
|
declare type MigrationConfig = {
|
|
5
5
|
migrationsPath: string;
|
|
@@ -48,7 +48,7 @@ declare type ChangeItem = [
|
|
|
48
48
|
dropMode?: DropMode;
|
|
49
49
|
}
|
|
50
50
|
] | [action: 'change', from: ChangeArg, to: ChangeArg, options?: ChangeOptions] | ['rename', string];
|
|
51
|
-
declare type TableChanger =
|
|
51
|
+
declare type TableChanger = MigrationColumnTypes & TableChangeMethods;
|
|
52
52
|
declare type TableChangeData = Record<string, ChangeItem | EmptyObject>;
|
|
53
53
|
|
|
54
54
|
declare type DropMode = 'CASCADE' | 'RESTRICT';
|
|
@@ -57,7 +57,12 @@ declare type TableOptions = {
|
|
|
57
57
|
comment?: string;
|
|
58
58
|
noPrimaryKey?: boolean;
|
|
59
59
|
};
|
|
60
|
-
declare type
|
|
60
|
+
declare type TextColumnCreator = () => TextColumn;
|
|
61
|
+
declare type MigrationColumnTypes = Omit<ColumnTypes, 'text' | 'string'> & {
|
|
62
|
+
text: TextColumnCreator;
|
|
63
|
+
string: TextColumnCreator;
|
|
64
|
+
};
|
|
65
|
+
declare type ColumnsShapeCallback = (t: MigrationColumnTypes & {
|
|
61
66
|
raw: typeof raw;
|
|
62
67
|
}) => ColumnsShape;
|
|
63
68
|
declare type ChangeTableOptions = {
|
|
@@ -100,8 +105,8 @@ declare class Migration extends TransactionAdapter {
|
|
|
100
105
|
changeTable(tableName: string, options: ChangeTableOptions, fn?: ChangeTableCallback): Promise<void>;
|
|
101
106
|
changeTable(tableName: string, fn: ChangeTableCallback): Promise<void>;
|
|
102
107
|
renameTable(from: string, to: string): Promise<void>;
|
|
103
|
-
addColumn(tableName: string, columnName: string, fn: (t:
|
|
104
|
-
dropColumn(tableName: string, columnName: string, fn: (t:
|
|
108
|
+
addColumn(tableName: string, columnName: string, fn: (t: MigrationColumnTypes) => ColumnType): Promise<void>;
|
|
109
|
+
dropColumn(tableName: string, columnName: string, fn: (t: MigrationColumnTypes) => ColumnType): Promise<void>;
|
|
105
110
|
addIndex(tableName: string, columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): Promise<void>;
|
|
106
111
|
dropIndex(tableName: string, columns: MaybeArray<string | IndexColumnOptions>, options?: IndexOptions): Promise<void>;
|
|
107
112
|
addForeignKey(tableName: string, columns: [string, ...string[]], foreignTable: string, foreignColumns: [string, ...string[]], options?: ForeignKeyOptions): Promise<void>;
|
|
@@ -132,4 +137,4 @@ declare const change: (fn: ChangeCallback) => void;
|
|
|
132
137
|
|
|
133
138
|
declare const rakeDb: (options: MaybeArray<AdapterOptions>, partialConfig?: Partial<MigrationConfig>, args?: string[]) => Promise<void>;
|
|
134
139
|
|
|
135
|
-
export { ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnIndex, ColumnsShapeCallback, DropMode, ExtensionOptions, JoinTableOptions, Migration, TableOptions, change, createDb, dropDb, generate, migrate, rakeDb, resetDb, rollback };
|
|
140
|
+
export { ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnIndex, ColumnsShapeCallback, DropMode, ExtensionOptions, JoinTableOptions, Migration, MigrationColumnTypes, TableOptions, change, createDb, dropDb, generate, migrate, rakeDb, resetDb, rollback };
|
package/dist/index.esm.js
CHANGED
|
@@ -423,7 +423,13 @@ class UnknownColumn extends ColumnType {
|
|
|
423
423
|
const createJoinTable = async (migration, up, tables, options, fn) => {
|
|
424
424
|
const tableName = options.tableName || joinWords(...tables);
|
|
425
425
|
if (!up) {
|
|
426
|
-
return createTable(
|
|
426
|
+
return createTable(
|
|
427
|
+
migration,
|
|
428
|
+
up,
|
|
429
|
+
tableName,
|
|
430
|
+
__spreadProps$1(__spreadValues$2({}, options), { noPrimaryKey: true }),
|
|
431
|
+
() => ({})
|
|
432
|
+
);
|
|
427
433
|
}
|
|
428
434
|
const tablesWithPrimaryKeys = await Promise.all(
|
|
429
435
|
tables.map(async (table) => {
|