rake-db 2.2.1 → 2.2.4
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/CHANGELOG.md +25 -0
- package/db.ts +8 -0
- package/dist/index.d.ts +12 -4
- package/dist/index.esm.js +172 -120
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +172 -119
- package/dist/index.js.map +1 -1
- package/migrations/20221017200326_createChatUser.ts +3 -0
- package/package.json +2 -2
- package/src/commands/migrateOrRollback.test.ts +86 -12
- package/src/commands/migrateOrRollback.ts +23 -4
- package/src/common.ts +7 -1
- package/src/migration/changeTable.ts +2 -1
- package/src/migration/createJoinTable.ts +4 -0
- package/src/migration/createTable.ts +2 -1
- package/src/migration/migration.ts +14 -3
- package/src/rakeDb.ts +19 -6
- package/src/test-utils.ts +15 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# rake-db
|
|
2
2
|
|
|
3
|
+
## 2.2.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add --code cli argument to rake-db
|
|
8
|
+
- Improve codegen
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
- pqb@0.8.4
|
|
12
|
+
|
|
13
|
+
## 2.2.3
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
- pqb@0.8.3
|
|
19
|
+
|
|
20
|
+
## 2.2.2
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- Add code generator to change project files after migrations
|
|
25
|
+
- Updated dependencies
|
|
26
|
+
- pqb@0.8.2
|
|
27
|
+
|
|
3
28
|
## 2.2.1
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/db.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { config } from 'dotenv';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { rakeDb } from './src/rakeDb';
|
|
4
4
|
import { AdapterOptions } from 'pqb';
|
|
5
|
+
import { appCodeUpdater } from '../orm/src';
|
|
5
6
|
|
|
6
7
|
config({ path: path.resolve(process.cwd(), '.env.local') });
|
|
7
8
|
config();
|
|
@@ -22,4 +23,11 @@ if (databaseURLTest) {
|
|
|
22
23
|
|
|
23
24
|
rakeDb(options, {
|
|
24
25
|
migrationsPath: path.resolve(process.cwd(), 'migrations'),
|
|
26
|
+
appCodeUpdater: appCodeUpdater({
|
|
27
|
+
tablePath: (tableName) => `app/tables/${tableName}.ts`,
|
|
28
|
+
baseTablePath: 'app/lib/baseTable.ts',
|
|
29
|
+
baseTableName: 'BaseTable',
|
|
30
|
+
mainFilePath: 'app/db.ts',
|
|
31
|
+
}),
|
|
32
|
+
useCodeUpdaterByDefault: false,
|
|
25
33
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as pqb from 'pqb';
|
|
2
|
-
import { EmptyObject, RawExpression, ColumnType, ColumnTypes, raw, ColumnsShape, TransactionAdapter, QueryLogObject, QueryResultRow, QueryInput, TypeParsers, QueryResult, QueryArraysResult, MaybeArray, IndexColumnOptions, IndexOptions, ForeignKeyOptions, TextColumn, NoPrimaryKeyOption, TableData, SingleColumnIndexOptions, QueryLogOptions
|
|
2
|
+
import { EmptyObject, RawExpression, ColumnType, ColumnTypes, raw, ColumnsShape, TransactionAdapter, AdapterOptions, QueryLogObject, QueryResultRow, QueryInput, TypeParsers, QueryResult, QueryArraysResult, MaybeArray, IndexColumnOptions, IndexOptions, ForeignKeyOptions, TextColumn, NoPrimaryKeyOption, TableData, SingleColumnIndexOptions, QueryLogOptions } from 'pqb';
|
|
3
3
|
|
|
4
4
|
declare function add(item: ColumnType, options?: {
|
|
5
5
|
dropMode?: DropMode;
|
|
@@ -63,8 +63,10 @@ declare type ExtensionOptions = {
|
|
|
63
63
|
declare class Migration extends TransactionAdapter {
|
|
64
64
|
up: boolean;
|
|
65
65
|
options: RakeDbConfig;
|
|
66
|
+
adapterOptions: AdapterOptions;
|
|
67
|
+
appCodeUpdaterCache: object;
|
|
66
68
|
log?: QueryLogObject;
|
|
67
|
-
constructor(tx: TransactionAdapter, up: boolean, options: RakeDbConfig);
|
|
69
|
+
constructor(tx: TransactionAdapter, up: boolean, options: RakeDbConfig, adapterOptions: AdapterOptions, appCodeUpdaterCache: object);
|
|
68
70
|
query<T extends QueryResultRow = any>(query: QueryInput, types?: TypeParsers, log?: QueryLogObject | undefined): Promise<QueryResult<T>>;
|
|
69
71
|
arrays<R extends any[] = any[]>(query: QueryInput, types?: TypeParsers, log?: QueryLogObject | undefined): Promise<QueryArraysResult<R>>;
|
|
70
72
|
createTable(tableName: string, options: TableOptions, fn: ColumnsShapeCallback): Promise<void>;
|
|
@@ -104,6 +106,7 @@ declare class Migration extends TransactionAdapter {
|
|
|
104
106
|
columnExists(tableName: string, columnName: string): Promise<boolean>;
|
|
105
107
|
constraintExists(constraintName: string): Promise<boolean>;
|
|
106
108
|
}
|
|
109
|
+
declare const runCodeUpdater: (migration: Migration, ast: RakeDbAst) => Promise<void> | undefined;
|
|
107
110
|
|
|
108
111
|
declare type RakeDbAst = RakeDbAst.Table | RakeDbAst.ChangeTable | RakeDbAst.RenameTable | RakeDbAst.Schema | RakeDbAst.Extension;
|
|
109
112
|
declare namespace RakeDbAst {
|
|
@@ -185,8 +188,13 @@ declare type RakeDbConfig = {
|
|
|
185
188
|
requireTs(path: string): void;
|
|
186
189
|
noPrimaryKey?: NoPrimaryKeyOption;
|
|
187
190
|
appCodeUpdater?: AppCodeUpdater;
|
|
191
|
+
useCodeUpdater?: boolean;
|
|
188
192
|
} & QueryLogOptions;
|
|
189
|
-
declare type AppCodeUpdater = (
|
|
193
|
+
declare type AppCodeUpdater = (params: {
|
|
194
|
+
ast: RakeDbAst;
|
|
195
|
+
options: AdapterOptions;
|
|
196
|
+
cache: object;
|
|
197
|
+
}) => Promise<void>;
|
|
190
198
|
|
|
191
199
|
declare const createDb: (arg: MaybeArray<AdapterOptions>, config: RakeDbConfig) => Promise<void>;
|
|
192
200
|
declare const dropDb: (arg: MaybeArray<AdapterOptions>) => Promise<void>;
|
|
@@ -202,4 +210,4 @@ declare const change: (fn: ChangeCallback) => void;
|
|
|
202
210
|
|
|
203
211
|
declare const rakeDb: (options: MaybeArray<AdapterOptions>, partialConfig?: Partial<RakeDbConfig>, args?: string[]) => Promise<void>;
|
|
204
212
|
|
|
205
|
-
export { AppCodeUpdater, ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnsShapeCallback, DropMode, ExtensionOptions, JoinTableOptions, Migration, MigrationColumnTypes, RakeDbAst, RakeDbConfig, TableOptions, change, createDb, dropDb, generate, migrate, rakeDb, resetDb, rollback };
|
|
213
|
+
export { AppCodeUpdater, ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnsShapeCallback, DropMode, ExtensionOptions, JoinTableOptions, Migration, MigrationColumnTypes, RakeDbAst, RakeDbConfig, TableOptions, change, createDb, dropDb, generate, migrate, rakeDb, resetDb, rollback, runCodeUpdater };
|