@biorate/migrations 0.28.3 → 0.29.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. package/.nyc_output/5c56cd30-e43b-4828-be0a-b7218c12d650.json +1 -0
  2. package/.nyc_output/processinfo/5c56cd30-e43b-4828-be0a-b7218c12d650.json +1 -0
  3. package/.nyc_output/processinfo/index.json +1 -0
  4. package/CHANGELOG.md +19 -0
  5. package/coverage/lcov-report/base.css +224 -0
  6. package/coverage/lcov-report/block-navigation.js +87 -0
  7. package/coverage/lcov-report/favicon.png +0 -0
  8. package/coverage/lcov-report/index.html +131 -0
  9. package/coverage/lcov-report/prettify.css +1 -0
  10. package/coverage/lcov-report/prettify.js +2 -0
  11. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  12. package/coverage/lcov-report/sorter.js +196 -0
  13. package/coverage/lcov.info +137 -0
  14. package/dist/tsconfig.build.tsbuildinfo +1 -1
  15. package/package.json +8 -8
  16. package/dist/src/default.config.js +0 -16
  17. package/dist/src/default.config.js.map +0 -1
  18. package/dist/src/errors.js +0 -3
  19. package/dist/src/errors.js.map +0 -1
  20. package/dist/src/index.js +0 -26
  21. package/dist/src/index.js.map +0 -1
  22. package/dist/src/interfaces.js +0 -1
  23. package/dist/src/interfaces.js.map +0 -1
  24. package/dist/src/root.js +0 -39
  25. package/dist/src/root.js.map +0 -1
  26. package/dist/src/types/index.js +0 -18
  27. package/dist/src/types/index.js.map +0 -1
  28. package/dist/src/types/migration.js +0 -48
  29. package/dist/src/types/migration.js.map +0 -1
  30. package/dist/src/types/sequelize.js +0 -51
  31. package/dist/src/types/sequelize.js.map +0 -1
  32. package/index.ts +0 -1
  33. package/src/default.config.ts +0 -15
  34. package/src/errors.ts +0 -7
  35. package/src/index.ts +0 -12
  36. package/src/interfaces.ts +0 -0
  37. package/src/root.ts +0 -15
  38. package/src/types/index.ts +0 -1
  39. package/src/types/migration.ts +0 -51
  40. package/src/types/sequelize.ts +0 -42
  41. package/tests/__mocks__/index.ts +0 -32
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Migration = void 0;
13
- const fs_1 = require("fs");
14
- const tools_1 = require("@biorate/tools");
15
- const inversion_1 = require("@biorate/inversion");
16
- let Migration = class Migration {
17
- get type() {
18
- return this.constructor.name.toLowerCase();
19
- }
20
- async scan(...args) {
21
- return (await fs_1.promises.readdir(this.path(...args))).map((item) => this.path(...args, item));
22
- }
23
- path(...args) {
24
- return tools_1.path.create(process.cwd(), this.config.get('migrations.directory', 'migrations'), this.type, ...args);
25
- }
26
- log(...args) {
27
- console.info(this.type, ...args, 'up!');
28
- }
29
- async initialize() {
30
- console.log(this.constructor.name);
31
- await this.process();
32
- }
33
- };
34
- __decorate([
35
- (0, inversion_1.inject)(inversion_1.Types.Config),
36
- __metadata("design:type", Object)
37
- ], Migration.prototype, "config", void 0);
38
- __decorate([
39
- (0, inversion_1.init)(),
40
- __metadata("design:type", Function),
41
- __metadata("design:paramtypes", []),
42
- __metadata("design:returntype", Promise)
43
- ], Migration.prototype, "initialize", null);
44
- Migration = __decorate([
45
- (0, inversion_1.injectable)()
46
- ], Migration);
47
- exports.Migration = Migration;
48
- //# sourceMappingURL=migration.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migration.js","sourceRoot":"","sources":["../../../src/types/migration.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__decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Sequelize = void 0;
13
- const fs_1 = require("fs");
14
- const tools_1 = require("@biorate/tools");
15
- const migration_1 = require("./migration");
16
- const sequelize_1 = require("@biorate/sequelize");
17
- const inversion_1 = require("@biorate/inversion");
18
- class Sequelize extends migration_1.Migration {
19
- async process() {
20
- for (const config of this.config.get('Sequelize', [])) {
21
- const paths = await this.scan(config.name);
22
- if (!paths.length)
23
- continue;
24
- const connection = this.sequelize.connection(config.name);
25
- const model = connection.define(this.config.get('migrations.tableName', 'migrations'), {
26
- name: {
27
- type: sequelize_1.DataType.CHAR,
28
- primaryKey: true,
29
- },
30
- }, { timestamps: false });
31
- await model.sync({});
32
- for (const p of paths) {
33
- const name = tools_1.path.basename(p);
34
- await connection.transaction(async () => {
35
- const item = await model.findOne({ where: { name } });
36
- if (item)
37
- return;
38
- await connection.query(await fs_1.promises.readFile(p, 'utf8'));
39
- await model.create({ name });
40
- this.log(config.name, name);
41
- });
42
- }
43
- }
44
- }
45
- }
46
- __decorate([
47
- (0, inversion_1.inject)(inversion_1.Types.Sequelize),
48
- __metadata("design:type", Object)
49
- ], Sequelize.prototype, "sequelize", void 0);
50
- exports.Sequelize = Sequelize;
51
- //# sourceMappingURL=sequelize.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"s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,CAAC,CAAC,CAAC;oBACrD,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;oBAC7B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAC9B,CAAC,CAAC,CAAC;aACJ;SACF;IACH,CAAC;CACF;AAhC0B;IAAxB,IAAA,kBAAM,EAAC,iBAAK,CAAC,SAAS,CAAC;;4CAA0C;AADpE,8BAiCC"}
package/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './src';
@@ -1,15 +0,0 @@
1
- import { container, Types } from '@biorate/inversion';
2
- import { IConfig } from '@biorate/config';
3
- import { FileConfig } from '@biorate/file-config';
4
- import { ISequelizeConnection, SequelizeConnector } from '@biorate/sequelize';
5
- import { Root } from './';
6
- import * as Migrations from './types';
7
-
8
- container.bind<IConfig>(Types.Config).to(FileConfig).inSingletonScope();
9
- container
10
- .bind<ISequelizeConnection>(Types.Sequelize)
11
- .to(SequelizeConnector)
12
- .inSingletonScope();
13
- container.bind<Migrations.Sequelize>(Migrations.Sequelize).toSelf().inSingletonScope();
14
- container.bind<Root>(Root).toSelf().inSingletonScope();
15
- container.get<Root>(Root).$run().catch(console.error);
package/src/errors.ts DELETED
@@ -1,7 +0,0 @@
1
- import { BaseError } from '@biorate/errors';
2
-
3
- // export class MongoDBCantConnectError extends BaseError {
4
- // public constructor(e: Error) {
5
- // super(`Can't connect to MongoDB: [%s]`, [e.message]);
6
- // }
7
- // }
package/src/index.ts DELETED
@@ -1,12 +0,0 @@
1
- import {container} from "@biorate/inversion";
2
-
3
- export * from './root';
4
- export * from './types/migration';
5
- export * from './types';
6
-
7
- require(process.env.MIGRATIONS_CONFIG
8
- ? process.cwd() + process.env.MIGRATIONS_CONFIG
9
- : './default.config');
10
- require(process.env.MIGRATIONS_ROOT
11
- ? process.cwd() + process.env.MIGRATIONS_ROOT
12
- : './root');
package/src/interfaces.ts DELETED
File without changes
package/src/root.ts DELETED
@@ -1,15 +0,0 @@
1
- import { IConfig } from '@biorate/config';
2
- import { init, injectable, inject, Types, Core, container } from '@biorate/inversion';
3
- import * as Migrations from './types';
4
-
5
- @injectable()
6
- export class Root extends Core() {
7
- @inject(Types.Config) public config: IConfig;
8
- @inject(Migrations.Sequelize) public sequelize: Migrations.Sequelize;
9
-
10
- @init() protected async initialize() {
11
- process.exit();
12
- }
13
- }
14
-
15
- Core.log = null;
@@ -1 +0,0 @@
1
- export * from './sequelize';
@@ -1,51 +0,0 @@
1
- import { promises as fs } from 'fs';
2
- import { path } from '@biorate/tools';
3
- import { init, injectable, inject, Types } from '@biorate/inversion';
4
- import { IConfig } from '@biorate/config';
5
- /**
6
- * @description Abstract migration class
7
- */
8
- @injectable()
9
- export abstract class Migration {
10
- @inject(Types.Config) protected config: IConfig;
11
- /**
12
- * @description Get migration type
13
- */
14
- protected get type() {
15
- return this.constructor.name.toLowerCase();
16
- }
17
- /**
18
- * @description Scan migration directory
19
- */
20
- protected async scan(...args: string[]) {
21
- return (await fs.readdir(this.path(...args))).map((item) => this.path(...args, item));
22
- }
23
- /**
24
- * @description Create path to migrations directory
25
- */
26
- protected path(...args: string[]) {
27
- return path.create(
28
- process.cwd(),
29
- this.config.get<string>('migrations.directory', 'migrations'),
30
- this.type,
31
- ...args,
32
- );
33
- }
34
- /**
35
- * @description Logging method
36
- */
37
- protected log(...args: string[]) {
38
- console.info(this.type, ...args, 'up!');
39
- }
40
- /**
41
- * @description Initialize method
42
- */
43
- @init() protected async initialize() {
44
- console.log(this.constructor.name);
45
- await this.process();
46
- }
47
- /**
48
- * @description Abstract async process method
49
- */
50
- protected abstract process(): Promise<void>;
51
- }
@@ -1,42 +0,0 @@
1
- import { promises as fs } from 'fs';
2
- import { path } from '@biorate/tools';
3
- import { Migration } from './migration';
4
- import { ISequelizeConnector, ISequelizeConfig, DataType } from '@biorate/sequelize';
5
- import { inject, Types } from '@biorate/inversion';
6
- /**
7
- * @description Sequelize migration class
8
- */
9
- export class Sequelize extends Migration {
10
- @inject(Types.Sequelize) protected sequelize: ISequelizeConnector;
11
- /**
12
- * @description Sequelize process method realization
13
- */
14
- protected async process() {
15
- for (const config of this.config.get<ISequelizeConfig[]>('Sequelize', [])) {
16
- const paths = await this.scan(config.name);
17
- if (!paths.length) continue;
18
- const connection = this.sequelize.connection(config.name);
19
- const model = connection.define(
20
- this.config.get<string>('migrations.tableName', 'migrations'),
21
- {
22
- name: {
23
- type: DataType.CHAR,
24
- primaryKey: true,
25
- },
26
- },
27
- { timestamps: false },
28
- );
29
- await model.sync({});
30
- for (const p of paths) {
31
- const name = path.basename(p);
32
- await connection.transaction(async () => {
33
- const item = await model.findOne({ where: { name } });
34
- if (item) return;
35
- await connection.query(await fs.readFile(p, 'utf8'));
36
- await model.create({ name });
37
- this.log(config.name, name);
38
- });
39
- }
40
- }
41
- }
42
- }
@@ -1,32 +0,0 @@
1
- import { use } from 'chai';
2
- import { unlinkSync } from 'fs';
3
- import { tmpdir } from 'os';
4
- import { join } from 'path';
5
- import { jestSnapshotPlugin } from 'mocha-chai-jest-snapshot';
6
- import { container, Types } from '@biorate/inversion';
7
- import { IConfig } from '@biorate/config';
8
- import '../../src/default.config';
9
-
10
- use(jestSnapshotPlugin());
11
-
12
- const storage = join(tmpdir(), 'sqlite-test.db');
13
-
14
- try {
15
- unlinkSync(storage);
16
- } catch {}
17
-
18
- container.get<IConfig>(Types.Config).merge({
19
- Sequelize: [
20
- {
21
- name: 'sqlite',
22
- options: {
23
- logging: false,
24
- dialect: 'sqlite',
25
- storage,
26
- },
27
- },
28
- ],
29
- migrations: {
30
- directory: '/tests/migrations',
31
- },
32
- });