sasat 0.19.17 → 0.19.18

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/lib/cli/cli.js CHANGED
File without changes
@@ -6,6 +6,19 @@ export var Direction;
6
6
  Direction["Up"] = "up";
7
7
  Direction["Down"] = "down";
8
8
  })(Direction || (Direction = {}));
9
+ const calcRunMigrationFileNames = (records) => {
10
+ const result = [];
11
+ records.forEach(it => {
12
+ if (it.direction === Direction.Down) {
13
+ if (result[result.length] !== it.name)
14
+ throw new Error('Invalid migration history: `down` migration must be the same migration as the last `up` migration ');
15
+ result.pop();
16
+ return;
17
+ }
18
+ result.push(it.name);
19
+ });
20
+ return result;
21
+ };
9
22
  export const getCurrentMigration = async () => {
10
23
  const migrationTable = config().migration.table;
11
24
  const files = getMigrationFileNames();
@@ -15,13 +28,19 @@ export const getCurrentMigration = async () => {
15
28
  "direction enum('up', 'down') not null, migrated_at timestamp default current_timestamp)");
16
29
  const result = await client.rawQuery(`SELECT name, direction
17
30
  FROM ${migrationTable}
18
- ORDER BY id DESC LIMIT 1`);
31
+ ORDER BY migrated_at ASC LIMIT 1`);
19
32
  if (!result.length)
20
33
  return;
21
- if (result[0].direction === Direction.Up)
22
- return result[0].name;
23
- const index = files.indexOf(result[0].name);
24
- if (index === -1)
25
- throw new Error(`${result[0].name} not found`);
26
- return files[index - 1];
34
+ const runs = calcRunMigrationFileNames(result);
35
+ if (runs.length)
36
+ return;
37
+ runs.forEach((run, i) => {
38
+ if (files[i] !== run)
39
+ throw new Error(`\
40
+ Invalid migration order: Migration must be performed in the same order
41
+ Found : ${files[i]}
42
+ in migration history: ${run}`);
43
+ });
44
+ console.log(runs[runs.length - 1]);
45
+ return runs[runs.length - 1];
27
46
  };
@@ -31,13 +31,13 @@ export declare abstract class SasatDBDatasource<Entity extends EntityType, Ident
31
31
  abstract readonly fields: string[];
32
32
  protected abstract readonly primaryKeys: string[];
33
33
  protected abstract readonly identifyFields: string[];
34
- protected abstract readonly autoIncrementColumn?: string;
34
+ protected abstract readonly autoIncrementColumn?: string | undefined;
35
35
  protected queryLogger: (sql: string) => void;
36
36
  protected commandLogger: (sql: string) => void;
37
37
  constructor(client?: SQLExecutor);
38
38
  protected abstract getDefaultValueString(): Partial<{
39
- [P in keyof Entity]: Entity[P] | string | null;
40
- }>;
39
+ [P in keyof Entity]: Entity[P] | string | null | never;
40
+ }> | never;
41
41
  create(entity: Creatable, upsert?: {
42
42
  updateColumns: string[];
43
43
  }): Promise<Entity>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sasat",
3
- "version": "0.19.17",
3
+ "version": "0.19.18",
4
4
  "repository": "https://github.com/nin138/sasat.git",
5
5
  "author": "nin138 <ninian138@gmail.com>",
6
6
  "license": "MIT",
@@ -9,9 +9,7 @@
9
9
  "files": [
10
10
  "lib"
11
11
  ],
12
- "bin": {
13
- "sasat": "lib/cli/cli.js"
14
- },
12
+ "bin": "lib/cli/cli.js",
15
13
  "scripts": {
16
14
  "start": "env-cmd .env ts-node ./index.ts",
17
15
  "build": "yarn tsc",
@@ -74,5 +72,6 @@
74
72
  "yarn format"
75
73
  ]
76
74
  },
77
- "type": "module"
75
+ "type": "module",
76
+ "packageManager": "yarn@3.6.0"
78
77
  }