@biorate/migrations 1.165.14 → 2.0.0
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/cjs/index.js +0 -1
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/src/default.config.js +2 -3
- package/dist/cjs/src/errors.js +0 -1
- package/dist/cjs/src/event-emitter.js +7 -0
- package/dist/cjs/src/index.js +3 -5
- package/dist/cjs/src/interfaces.js +0 -1
- package/dist/cjs/src/require-cjs.js +5 -0
- package/dist/cjs/src/require-esm.js +5 -0
- package/dist/cjs/src/root.js +3 -4
- package/dist/cjs/src/types/amqp.js +2 -4
- package/dist/cjs/src/types/clickhouse.js +0 -1
- package/dist/cjs/src/types/index.js +0 -1
- package/dist/cjs/src/types/kafka.js +2 -4
- package/dist/cjs/src/types/migration.js +0 -1
- package/dist/cjs/src/types/minio.js +2 -4
- package/dist/cjs/src/types/mongodb.js +2 -4
- package/dist/cjs/src/types/schema-registry.js +2 -4
- package/dist/cjs/src/types/sequelize.js +0 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/src/{default.config.mjs → default.config.js} +1 -2
- package/dist/esm/src/{errors.mjs → errors.js} +0 -1
- package/dist/esm/src/event-emitter.js +3 -0
- package/dist/esm/src/index.js +8 -0
- package/dist/esm/src/interfaces.js +1 -0
- package/dist/esm/src/require-cjs.js +2 -0
- package/dist/esm/src/require-esm.js +2 -0
- package/dist/esm/src/{root.mjs → root.js} +3 -4
- package/dist/esm/src/types/{amqp.mjs → amqp.js} +3 -5
- package/dist/esm/src/types/{clickhouse.mjs → clickhouse.js} +1 -2
- package/dist/esm/src/types/index.js +7 -0
- package/dist/esm/src/types/{kafka.mjs → kafka.js} +3 -5
- package/dist/esm/src/types/{migration.mjs → migration.js} +0 -1
- package/dist/esm/src/types/{minio.mjs → minio.js} +3 -5
- package/dist/esm/src/types/{mongodb.mjs → mongodb.js} +3 -5
- package/dist/esm/src/types/{schema-registry.mjs → schema-registry.js} +4 -6
- package/dist/esm/src/types/{sequelize.mjs → sequelize.js} +1 -2
- package/dist/types/src/event-emitter.d.ts +3 -0
- package/dist/types/src/require-cjs.d.ts +1 -0
- package/dist/types/src/require-esm.d.ts +1 -0
- package/dist/types/src/root.d.ts +3 -3
- package/package.json +48 -23
- package/.nyc_output/5dd7a2aa-147b-4304-84bf-effac0f982fd.json +0 -1
- package/.nyc_output/8ed41da4-40ec-49dc-8dbc-0ebaa3847e76.json +0 -1
- package/.nyc_output/f0726e72-3148-4051-b1f5-0768a33e5118.json +0 -1
- package/.nyc_output/processinfo/5dd7a2aa-147b-4304-84bf-effac0f982fd.json +0 -1
- package/.nyc_output/processinfo/8ed41da4-40ec-49dc-8dbc-0ebaa3847e76.json +0 -1
- package/.nyc_output/processinfo/f0726e72-3148-4051-b1f5-0768a33e5118.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/CHANGELOG.md +0 -1179
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/clover.xml +0 -188
- package/coverage/coverage-final.json +0 -13
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -146
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -210
- package/coverage/src/errors.ts.html +0 -112
- package/coverage/src/index.html +0 -131
- package/coverage/src/root.ts.html +0 -385
- package/coverage/src/types/amqp.ts.html +0 -223
- package/coverage/src/types/clickhouse.ts.html +0 -271
- package/coverage/src/types/index.html +0 -236
- package/coverage/src/types/index.ts.html +0 -106
- package/coverage/src/types/kafka.ts.html +0 -190
- package/coverage/src/types/migration.ts.html +0 -361
- package/coverage/src/types/minio.ts.html +0 -202
- package/coverage/src/types/mongodb.ts.html +0 -193
- package/coverage/src/types/schema-registry.ts.html +0 -250
- package/coverage/src/types/sequelize.ts.html +0 -229
- package/coverage/tests/__mocks__/index.html +0 -116
- package/coverage/tests/__mocks__/index.ts.html +0 -208
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/src/default.config.js.map +0 -1
- package/dist/cjs/src/errors.js.map +0 -1
- package/dist/cjs/src/index.js.map +0 -1
- package/dist/cjs/src/interfaces.js.map +0 -1
- package/dist/cjs/src/root.js.map +0 -1
- package/dist/cjs/src/types/amqp.js.map +0 -1
- package/dist/cjs/src/types/clickhouse.js.map +0 -1
- package/dist/cjs/src/types/index.js.map +0 -1
- package/dist/cjs/src/types/kafka.js.map +0 -1
- package/dist/cjs/src/types/migration.js.map +0 -1
- package/dist/cjs/src/types/minio.js.map +0 -1
- package/dist/cjs/src/types/mongodb.js.map +0 -1
- package/dist/cjs/src/types/schema-registry.js.map +0 -1
- package/dist/cjs/src/types/sequelize.js.map +0 -1
- package/dist/cjs/tsconfig.build.cjs.tsbuildinfo +0 -1
- package/dist/esm/index.mjs +0 -2
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/src/default.config.mjs.map +0 -1
- package/dist/esm/src/errors.mjs.map +0 -1
- package/dist/esm/src/index.mjs +0 -10
- package/dist/esm/src/index.mjs.map +0 -1
- package/dist/esm/src/interfaces.mjs +0 -2
- package/dist/esm/src/interfaces.mjs.map +0 -1
- package/dist/esm/src/root.mjs.map +0 -1
- package/dist/esm/src/types/amqp.mjs.map +0 -1
- package/dist/esm/src/types/clickhouse.mjs.map +0 -1
- package/dist/esm/src/types/index.mjs +0 -8
- package/dist/esm/src/types/index.mjs.map +0 -1
- package/dist/esm/src/types/kafka.mjs.map +0 -1
- package/dist/esm/src/types/migration.mjs.map +0 -1
- package/dist/esm/src/types/minio.mjs.map +0 -1
- package/dist/esm/src/types/mongodb.mjs.map +0 -1
- package/dist/esm/src/types/schema-registry.mjs.map +0 -1
- package/dist/esm/src/types/sequelize.mjs.map +0 -1
- package/dist/esm/tsconfig.build.esm.tsbuildinfo +0 -1
- package/dist/index.js +0 -18
- package/dist/index.js.map +0 -1
- package/dist/src/default.config.js +0 -6
- package/dist/src/default.config.js.map +0 -1
- package/dist/src/errors.js +0 -13
- package/dist/src/errors.js.map +0 -1
- package/dist/src/index.js +0 -26
- package/dist/src/index.js.map +0 -1
- package/dist/src/interfaces.js +0 -2
- package/dist/src/interfaces.js.map +0 -1
- package/dist/src/root.js +0 -163
- package/dist/src/root.js.map +0 -1
- package/dist/src/types/amqp.js +0 -35
- package/dist/src/types/amqp.js.map +0 -1
- package/dist/src/types/clickhouse.js +0 -66
- package/dist/src/types/clickhouse.js.map +0 -1
- package/dist/src/types/index.js +0 -24
- package/dist/src/types/index.js.map +0 -1
- package/dist/src/types/kafka.js +0 -31
- package/dist/src/types/kafka.js.map +0 -1
- package/dist/src/types/migration.js +0 -70
- package/dist/src/types/migration.js.map +0 -1
- package/dist/src/types/minio.js +0 -39
- package/dist/src/types/minio.js.map +0 -1
- package/dist/src/types/mongodb.js +0 -34
- package/dist/src/types/mongodb.js.map +0 -1
- package/dist/src/types/schema-registry.js +0 -52
- package/dist/src/types/schema-registry.js.map +0 -1
- package/dist/src/types/sequelize.js +0 -43
- package/dist/src/types/sequelize.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/tsconfig.build.types.tsbuildinfo +0 -1
- package/index.d.ts +0 -26
- package/index.ts +0 -1
- package/src/default.config.ts +0 -4
- package/src/errors.ts +0 -9
- package/src/index.ts +0 -10
- package/src/interfaces.ts +0 -0
- package/src/root.ts +0 -100
- package/src/types/amqp.ts +0 -46
- package/src/types/clickhouse.ts +0 -62
- package/src/types/index.ts +0 -7
- package/src/types/kafka.ts +0 -35
- package/src/types/migration.ts +0 -92
- package/src/types/minio.ts +0 -39
- package/src/types/mongodb.ts +0 -36
- package/src/types/schema-registry.ts +0 -55
- package/src/types/sequelize.ts +0 -48
- package/tsconfig.build.json +0 -5
- package/tsconfig.json +0 -9
package/index.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'fs';
|
|
2
|
-
import { Core, inject, Types } from '@biorate/inversion';
|
|
3
|
-
import { IConfig } from '@biorate/config';
|
|
4
|
-
import * as Migrations from './src/types';
|
|
5
|
-
|
|
6
|
-
declare module '@biorate/migrations' {
|
|
7
|
-
export class Root extends Core() {
|
|
8
|
-
public config: IConfig;
|
|
9
|
-
public sequelize: Migrations.Sequelize;
|
|
10
|
-
protected initialize(): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export abstract class Migration {
|
|
14
|
-
protected config: IConfig;
|
|
15
|
-
protected get type(): string;
|
|
16
|
-
protected scan(...args: string[]): Promise<string[]>;
|
|
17
|
-
protected path(...args: string[]): string;
|
|
18
|
-
protected log(...args: string[]): void;
|
|
19
|
-
protected initialize(): Promise<void>;
|
|
20
|
-
protected abstract process(): Promise<void>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class Sequelize extends Migration {
|
|
24
|
-
protected process(): Promise<void>;
|
|
25
|
-
}
|
|
26
|
-
}
|
package/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './src';
|
package/src/default.config.ts
DELETED
package/src/errors.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './root';
|
|
2
|
-
export * from './types/migration';
|
|
3
|
-
export * from './types';
|
|
4
|
-
|
|
5
|
-
require(process.env.MIGRATIONS_CONFIG
|
|
6
|
-
? process.cwd() + process.env.MIGRATIONS_CONFIG
|
|
7
|
-
: './default.config');
|
|
8
|
-
require(process.env.MIGRATIONS_ROOT
|
|
9
|
-
? process.cwd() + process.env.MIGRATIONS_ROOT
|
|
10
|
-
: './root');
|
package/src/interfaces.ts
DELETED
|
File without changes
|
package/src/root.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import { init, injectable, inject, Types, Core, container } from '@biorate/inversion';
|
|
3
|
-
import { Config, IConfig } from '@biorate/config';
|
|
4
|
-
import { ConfigLoader } from '@biorate/config-loader';
|
|
5
|
-
import { IVaultConnector, VaultConnector } from '@biorate/vault';
|
|
6
|
-
import { IProxyConnector, ProxyConnector } from '@biorate/proxy';
|
|
7
|
-
import * as Migrations from './types';
|
|
8
|
-
import { ConfigLoaderEnv } from '@biorate/config-loader-env';
|
|
9
|
-
import { ConfigLoaderFs } from '@biorate/config-loader-fs';
|
|
10
|
-
import { ConfigLoaderVault } from '@biorate/config-loader-vault';
|
|
11
|
-
import { ISequelizeConnector, SequelizeConnector } from '@biorate/sequelize';
|
|
12
|
-
import { IMinioConnector, MinioConnector } from '@biorate/minio';
|
|
13
|
-
import { IMongoDBConnector, MongoDBConnector } from '@biorate/mongodb';
|
|
14
|
-
import { ClickhouseConnector, IClickhouseConnector } from '@biorate/clickhouse';
|
|
15
|
-
import { AmqpConnector, IAmqpConnector } from '@biorate/amqp';
|
|
16
|
-
import { IKafkaJSAdminConnector, KafkaJSAdminConnector } from '@biorate/kafkajs';
|
|
17
|
-
import {
|
|
18
|
-
ISchemaRegistryConnector,
|
|
19
|
-
SchemaRegistryConnector,
|
|
20
|
-
} from '@biorate/schema-registry';
|
|
21
|
-
|
|
22
|
-
@injectable()
|
|
23
|
-
export class Root extends Core(EventEmitter) {
|
|
24
|
-
@inject(Types.Config) public readonly config: IConfig;
|
|
25
|
-
|
|
26
|
-
@inject(Types.ConfigLoaderEnv) public readonly configLoaderEnv: ConfigLoader;
|
|
27
|
-
|
|
28
|
-
@inject(Types.ConfigLoaderFs) public readonly configLoaderFs: ConfigLoader;
|
|
29
|
-
|
|
30
|
-
@inject(Types.ConfigLoaderVault) public readonly configLoaderVault: ConfigLoader;
|
|
31
|
-
|
|
32
|
-
@inject(Types.Vault) public readonly vault: IVaultConnector;
|
|
33
|
-
|
|
34
|
-
@inject(Types.Proxy) public readonly proxy: IProxyConnector;
|
|
35
|
-
|
|
36
|
-
@inject(Migrations.Sequelize) public readonly sequelize: Migrations.Sequelize;
|
|
37
|
-
|
|
38
|
-
@inject(Migrations.Minio) public readonly minio: Migrations.Minio;
|
|
39
|
-
|
|
40
|
-
@inject(Migrations.Mongodb) public readonly mongodb: Migrations.Mongodb;
|
|
41
|
-
|
|
42
|
-
@inject(Migrations.Kafka) public readonly kafkaJSAdmin: Migrations.Kafka;
|
|
43
|
-
|
|
44
|
-
@inject(Migrations.Clickhouse) public readonly clickhouse: Migrations.Clickhouse;
|
|
45
|
-
|
|
46
|
-
@inject(Migrations.Amqp) public readonly amqp: Migrations.Amqp;
|
|
47
|
-
|
|
48
|
-
@inject(Migrations.SchemaRegistry)
|
|
49
|
-
public readonly schemaRegistry: Migrations.SchemaRegistry;
|
|
50
|
-
|
|
51
|
-
@init() protected async initialize() {
|
|
52
|
-
process.exit(0);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
Core.log = null;
|
|
58
|
-
|
|
59
|
-
container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
|
|
60
|
-
container
|
|
61
|
-
.bind<ConfigLoader>(Types.ConfigLoaderEnv)
|
|
62
|
-
.to(ConfigLoaderEnv)
|
|
63
|
-
.inSingletonScope();
|
|
64
|
-
container.bind<ConfigLoader>(Types.ConfigLoaderFs).to(ConfigLoaderFs).inSingletonScope();
|
|
65
|
-
container
|
|
66
|
-
.bind<ConfigLoader>(Types.ConfigLoaderVault)
|
|
67
|
-
.to(ConfigLoaderVault)
|
|
68
|
-
.inSingletonScope();
|
|
69
|
-
container.bind<IVaultConnector>(Types.Vault).to(VaultConnector).inSingletonScope();
|
|
70
|
-
container
|
|
71
|
-
.bind<ISequelizeConnector>(Types.Sequelize)
|
|
72
|
-
.to(SequelizeConnector)
|
|
73
|
-
.inSingletonScope();
|
|
74
|
-
container.bind<IMinioConnector>(Types.Minio).to(MinioConnector).inSingletonScope();
|
|
75
|
-
container.bind<IMongoDBConnector>(Types.Mongodb).to(MongoDBConnector).inSingletonScope();
|
|
76
|
-
container
|
|
77
|
-
.bind<IClickhouseConnector>(Types.Clickhouse)
|
|
78
|
-
.to(ClickhouseConnector)
|
|
79
|
-
.inSingletonScope();
|
|
80
|
-
container.bind<IAmqpConnector>(Types.Amqp).to(AmqpConnector).inSingletonScope();
|
|
81
|
-
container
|
|
82
|
-
.bind<IKafkaJSAdminConnector>(Types.Kafka)
|
|
83
|
-
.to(KafkaJSAdminConnector)
|
|
84
|
-
.inSingletonScope();
|
|
85
|
-
container.bind<IProxyConnector>(Types.Proxy).to(ProxyConnector).inSingletonScope();
|
|
86
|
-
container
|
|
87
|
-
.bind<ISchemaRegistryConnector>(Types.SchemaRegistry)
|
|
88
|
-
.to(SchemaRegistryConnector)
|
|
89
|
-
.inSingletonScope();
|
|
90
|
-
container.bind<Migrations.Sequelize>(Migrations.Sequelize).toSelf().inSingletonScope();
|
|
91
|
-
container.bind<Migrations.Minio>(Migrations.Minio).toSelf().inSingletonScope();
|
|
92
|
-
container.bind<Migrations.Mongodb>(Migrations.Mongodb).toSelf().inSingletonScope();
|
|
93
|
-
container.bind<Migrations.Kafka>(Migrations.Kafka).toSelf().inSingletonScope();
|
|
94
|
-
container.bind<Migrations.Clickhouse>(Migrations.Clickhouse).toSelf().inSingletonScope();
|
|
95
|
-
container.bind<Migrations.Amqp>(Migrations.Amqp).toSelf().inSingletonScope();
|
|
96
|
-
container
|
|
97
|
-
.bind<Migrations.SchemaRegistry>(Migrations.SchemaRegistry)
|
|
98
|
-
.toSelf()
|
|
99
|
-
.inSingletonScope();
|
|
100
|
-
container.bind<Root>(Root).to(Root).inSingletonScope();
|
package/src/types/amqp.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { inject, Types } from '@biorate/inversion';
|
|
2
|
-
import { IConfig } from '@biorate/config';
|
|
3
|
-
import {
|
|
4
|
-
IAmqpConnector,
|
|
5
|
-
IAmqpConfig,
|
|
6
|
-
IAmqpConnection,
|
|
7
|
-
ChannelWrapper,
|
|
8
|
-
CreateChannelOpts,
|
|
9
|
-
} from '@biorate/amqp';
|
|
10
|
-
import { Migration } from './migration';
|
|
11
|
-
/**
|
|
12
|
-
* @description Amqp migration class
|
|
13
|
-
*/
|
|
14
|
-
export class Amqp extends Migration {
|
|
15
|
-
@inject(Types.Amqp) protected connector: IAmqpConnector;
|
|
16
|
-
/**
|
|
17
|
-
* @description Amqp process method realization
|
|
18
|
-
*/
|
|
19
|
-
protected async process() {
|
|
20
|
-
await this.forEach<IAmqpConfig, IAmqpConnection>(
|
|
21
|
-
'Amqp',
|
|
22
|
-
async (config, connection, paths) => {
|
|
23
|
-
const channel = connection.createChannel(
|
|
24
|
-
this.config.get<CreateChannelOpts>(
|
|
25
|
-
`migrations.Amqp.${config.name}.amqpChannelOptions`,
|
|
26
|
-
{},
|
|
27
|
-
),
|
|
28
|
-
);
|
|
29
|
-
await channel.waitForConnect();
|
|
30
|
-
await this.forEachPath(paths, async (file, name) => {
|
|
31
|
-
try {
|
|
32
|
-
await (
|
|
33
|
-
require(file) as (
|
|
34
|
-
channel: ChannelWrapper,
|
|
35
|
-
connection: IAmqpConnection,
|
|
36
|
-
config: IAmqpConfig,
|
|
37
|
-
globalConfig: IConfig,
|
|
38
|
-
) => Promise<void>
|
|
39
|
-
)(channel, connection, config, this.config);
|
|
40
|
-
this.log(config.name, name);
|
|
41
|
-
} catch (e) {}
|
|
42
|
-
});
|
|
43
|
-
},
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
}
|
package/src/types/clickhouse.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'fs';
|
|
2
|
-
import { inject, Types } from '@biorate/inversion';
|
|
3
|
-
import { Migration } from './migration';
|
|
4
|
-
import {
|
|
5
|
-
IClickhouseConnector,
|
|
6
|
-
IClickhouseConnection,
|
|
7
|
-
IClickhouseConfig,
|
|
8
|
-
} from '@biorate/clickhouse';
|
|
9
|
-
/**
|
|
10
|
-
* @description Clickhouse migration class
|
|
11
|
-
*/
|
|
12
|
-
export class Clickhouse extends Migration {
|
|
13
|
-
@inject(Types.Clickhouse) protected connector: IClickhouseConnector;
|
|
14
|
-
/**
|
|
15
|
-
* @description Clickhouse process method realization
|
|
16
|
-
*/
|
|
17
|
-
protected async process() {
|
|
18
|
-
await this.forEach<IClickhouseConfig, IClickhouseConnection>(
|
|
19
|
-
'Clickhouse',
|
|
20
|
-
async (config, connection, paths) => {
|
|
21
|
-
const tableName = this.config.get<string>('migrations.tableName', 'migrations');
|
|
22
|
-
const createQuery = `
|
|
23
|
-
CREATE TABLE IF NOT EXISTS {tableName:Identifier} (
|
|
24
|
-
name String
|
|
25
|
-
)
|
|
26
|
-
ENGINE = MergeTree()
|
|
27
|
-
PRIMARY KEY (name);
|
|
28
|
-
`;
|
|
29
|
-
await connection.command({
|
|
30
|
-
query: createQuery,
|
|
31
|
-
query_params: { tableName },
|
|
32
|
-
clickhouse_settings: {
|
|
33
|
-
wait_end_of_query: 1,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
await this.forEachPath(paths, async (file, name) => {
|
|
37
|
-
const cursor = await connection.query({
|
|
38
|
-
query: `SELECT * FROM {tableName:Identifier} WHERE name = {name:String};`,
|
|
39
|
-
query_params: { name, tableName },
|
|
40
|
-
format: 'JSON',
|
|
41
|
-
});
|
|
42
|
-
const { data } = await cursor.json<{ name: string }>();
|
|
43
|
-
if (data.length) return;
|
|
44
|
-
await connection.command({
|
|
45
|
-
query: await fs.readFile(file, 'utf8'),
|
|
46
|
-
clickhouse_settings: {
|
|
47
|
-
wait_end_of_query: 1,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
await connection.command({
|
|
51
|
-
query: `INSERT INTO {tableName:Identifier} (name) VALUES ({name:String})`,
|
|
52
|
-
query_params: { name, tableName },
|
|
53
|
-
clickhouse_settings: {
|
|
54
|
-
wait_end_of_query: 1,
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
this.log(config.name, name);
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
}
|
package/src/types/index.ts
DELETED
package/src/types/kafka.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { inject, Types } from '@biorate/inversion';
|
|
2
|
-
import { IConfig } from '@biorate/config';
|
|
3
|
-
import {
|
|
4
|
-
IKafkaJSAdminConnector,
|
|
5
|
-
IKafkaJSAdminConfig,
|
|
6
|
-
IKafkaJSAdminConnection,
|
|
7
|
-
} from '@biorate/kafkajs';
|
|
8
|
-
import { Migration } from './migration';
|
|
9
|
-
/**
|
|
10
|
-
* @description Kafka migration class
|
|
11
|
-
*/
|
|
12
|
-
export class Kafka extends Migration {
|
|
13
|
-
@inject(Types.Kafka) protected connector: IKafkaJSAdminConnector;
|
|
14
|
-
/**
|
|
15
|
-
* @description Kafka process method realization
|
|
16
|
-
*/
|
|
17
|
-
protected async process() {
|
|
18
|
-
await this.forEach<IKafkaJSAdminConfig, IKafkaJSAdminConnection>(
|
|
19
|
-
'KafkaJSAdmin',
|
|
20
|
-
async (config, connection, paths) =>
|
|
21
|
-
await this.forEachPath(paths, async (file, name) => {
|
|
22
|
-
try {
|
|
23
|
-
await (
|
|
24
|
-
require(file) as (
|
|
25
|
-
connection: IKafkaJSAdminConnection,
|
|
26
|
-
config: IKafkaJSAdminConfig,
|
|
27
|
-
globalConfig: IConfig,
|
|
28
|
-
) => Promise<void>
|
|
29
|
-
)(connection, config, this.config);
|
|
30
|
-
this.log(config.name, name);
|
|
31
|
-
} catch (e) {}
|
|
32
|
-
}),
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/types/migration.ts
DELETED
|
@@ -1,92 +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
|
-
import { IConnector, IConnectorConfig } from '@biorate/connector';
|
|
6
|
-
/**
|
|
7
|
-
* @description Abstract migration class
|
|
8
|
-
*/
|
|
9
|
-
@injectable()
|
|
10
|
-
export abstract class Migration {
|
|
11
|
-
/**
|
|
12
|
-
* @description config property
|
|
13
|
-
*/
|
|
14
|
-
@inject(Types.Config) protected config: IConfig;
|
|
15
|
-
/**
|
|
16
|
-
* @description connector property
|
|
17
|
-
*/
|
|
18
|
-
protected abstract connector: IConnector<IConnectorConfig>;
|
|
19
|
-
/**
|
|
20
|
-
* @description Get migration type
|
|
21
|
-
*/
|
|
22
|
-
protected get type() {
|
|
23
|
-
return this.constructor.name.toLowerCase();
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* @description Scan migration directory
|
|
27
|
-
*/
|
|
28
|
-
protected async scan(...args: string[]) {
|
|
29
|
-
try {
|
|
30
|
-
return (await fs.readdir(this.path(...args))).map((item) =>
|
|
31
|
-
this.path(...args, item),
|
|
32
|
-
);
|
|
33
|
-
} catch {
|
|
34
|
-
return <string[]>[];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* @description Create path to migrations directory
|
|
39
|
-
*/
|
|
40
|
-
protected path(...args: string[]) {
|
|
41
|
-
return path.create(
|
|
42
|
-
process.cwd(),
|
|
43
|
-
this.config.get<string>('migrations.directory', 'migrations'),
|
|
44
|
-
this.type,
|
|
45
|
-
...args,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* @description Logging method
|
|
50
|
-
*/
|
|
51
|
-
protected log(...args: string[]) {
|
|
52
|
-
console.info(this.type, ...args, 'up!');
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* @description Initialize method
|
|
56
|
-
*/
|
|
57
|
-
@init() protected async initialize() {
|
|
58
|
-
console.info(this.constructor.name);
|
|
59
|
-
await this.process();
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* @description For each migration item
|
|
63
|
-
*/
|
|
64
|
-
protected async forEach<T extends { name: string }, C>(
|
|
65
|
-
namespace: string,
|
|
66
|
-
callback: (config: T, connection: C, paths: string[]) => Promise<void>,
|
|
67
|
-
) {
|
|
68
|
-
for (const config of this.config.get<T[]>(namespace, [])) {
|
|
69
|
-
const paths = await this.scan(config.name);
|
|
70
|
-
if (!paths.length) continue;
|
|
71
|
-
const connection = this.connector.connection(config.name);
|
|
72
|
-
if (!connection) {
|
|
73
|
-
console.info(`${namespace} connection [%s] not exists, skip...`, config.name);
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
await callback(config, connection, paths);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* @description For each migration item
|
|
81
|
-
*/
|
|
82
|
-
protected async forEachPath(
|
|
83
|
-
paths: string[],
|
|
84
|
-
callback: (file: string, name: string) => Promise<void>,
|
|
85
|
-
) {
|
|
86
|
-
for (const p of paths) await callback(p, path.basename(p));
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* @description Abstract async process method
|
|
90
|
-
*/
|
|
91
|
-
protected abstract process(): Promise<void>;
|
|
92
|
-
}
|
package/src/types/minio.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { IMinioConnector, IMinioConfig, IMinioConnection } from '@biorate/minio';
|
|
2
|
-
import { IConfig } from '@biorate/config';
|
|
3
|
-
import { inject, Types } from '@biorate/inversion';
|
|
4
|
-
import { Migration } from './migration';
|
|
5
|
-
/**
|
|
6
|
-
* @description Minio migration class
|
|
7
|
-
*/
|
|
8
|
-
export class Minio extends Migration {
|
|
9
|
-
@inject(Types.Minio) protected connector: IMinioConnector;
|
|
10
|
-
/**
|
|
11
|
-
* @description Minio process method realization
|
|
12
|
-
*/
|
|
13
|
-
protected async process() {
|
|
14
|
-
await this.forEach<IMinioConfig, IMinioConnection>(
|
|
15
|
-
'Minio',
|
|
16
|
-
async (config, connection, paths) =>
|
|
17
|
-
await this.forEachPath(paths, async (file, name) => {
|
|
18
|
-
const tableName = this.config.get<string>('migrations.tableName', 'migrations');
|
|
19
|
-
try {
|
|
20
|
-
await connection.makeBucket(tableName, tableName);
|
|
21
|
-
} catch {}
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
await connection.getObject(tableName, name);
|
|
25
|
-
} catch (e) {
|
|
26
|
-
await (
|
|
27
|
-
require(file) as (
|
|
28
|
-
connection: IMinioConnection,
|
|
29
|
-
config: IMinioConfig,
|
|
30
|
-
globalConfig: IConfig,
|
|
31
|
-
) => Promise<void>
|
|
32
|
-
)(connection, config, this.config);
|
|
33
|
-
await connection.putObject(tableName, name, Buffer.from('1'));
|
|
34
|
-
this.log(config.name, name);
|
|
35
|
-
}
|
|
36
|
-
}),
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
}
|
package/src/types/mongodb.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { IMongoDBConfig, IMongoDBConnection, IMongoDBConnector } from '@biorate/mongodb';
|
|
2
|
-
import { IConfig } from '@biorate/config';
|
|
3
|
-
import { inject, Types } from '@biorate/inversion';
|
|
4
|
-
import { Migration } from './migration';
|
|
5
|
-
/**
|
|
6
|
-
* @description Mongodb migration class
|
|
7
|
-
*/
|
|
8
|
-
export class Mongodb extends Migration {
|
|
9
|
-
@inject(Types.Mongodb) protected connector: IMongoDBConnector;
|
|
10
|
-
/**
|
|
11
|
-
* @description Mongodb process method realization
|
|
12
|
-
*/
|
|
13
|
-
protected async process() {
|
|
14
|
-
await this.forEach<IMongoDBConfig, IMongoDBConnection>(
|
|
15
|
-
'MongoDB',
|
|
16
|
-
async (config, connection, paths) =>
|
|
17
|
-
await this.forEachPath(paths, async (file, name) => {
|
|
18
|
-
try {
|
|
19
|
-
await (
|
|
20
|
-
require(file) as (
|
|
21
|
-
connection: IMongoDBConnection,
|
|
22
|
-
config: IMongoDBConfig,
|
|
23
|
-
globalConfig: IConfig,
|
|
24
|
-
) => Promise<void>
|
|
25
|
-
)(connection, config, this.config);
|
|
26
|
-
await connection
|
|
27
|
-
.collection<{ _id: string }>(
|
|
28
|
-
this.config.get<string>('migrations.tableName', 'migrations'),
|
|
29
|
-
)
|
|
30
|
-
.insertOne({ _id: name });
|
|
31
|
-
this.log(config.name, name);
|
|
32
|
-
} catch (e) {}
|
|
33
|
-
}),
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { kebabCase } from 'lodash';
|
|
2
|
-
import { inject, Types } from '@biorate/inversion';
|
|
3
|
-
import {
|
|
4
|
-
ISchemaRegistryConnector,
|
|
5
|
-
ISchemaRegistryConfig,
|
|
6
|
-
ISchemaRegistryConnection,
|
|
7
|
-
ICompatibilities,
|
|
8
|
-
} from '@biorate/schema-registry';
|
|
9
|
-
import { Migration } from './migration';
|
|
10
|
-
import { SchemaRegistryWrongFileNameError } from '../errors';
|
|
11
|
-
/**
|
|
12
|
-
* @description Schema registry migration class
|
|
13
|
-
*/
|
|
14
|
-
export class SchemaRegistry extends Migration {
|
|
15
|
-
@inject(Types.SchemaRegistry) protected connector: ISchemaRegistryConnector;
|
|
16
|
-
/**
|
|
17
|
-
* @description Get migration type
|
|
18
|
-
*/
|
|
19
|
-
protected override get type() {
|
|
20
|
-
return kebabCase(this.constructor.name);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* @description Schema registry process method realization
|
|
24
|
-
*/
|
|
25
|
-
protected async process() {
|
|
26
|
-
await this.forEach<
|
|
27
|
-
ISchemaRegistryConfig & { compatibility?: ICompatibilities },
|
|
28
|
-
ISchemaRegistryConnection
|
|
29
|
-
>(
|
|
30
|
-
'SchemaRegistry',
|
|
31
|
-
async (config, connection, paths) =>
|
|
32
|
-
await this.forEachPath(paths, async (file, fullName) => {
|
|
33
|
-
const name = fullName.split('_')?.[1]?.replace('.json', '');
|
|
34
|
-
if (!name) throw new SchemaRegistryWrongFileNameError(fullName);
|
|
35
|
-
const schema = <Record<string, unknown>>require(file);
|
|
36
|
-
await connection.putConfig({
|
|
37
|
-
subject: name,
|
|
38
|
-
compatibility: config.compatibility ?? 'FORWARD',
|
|
39
|
-
});
|
|
40
|
-
try {
|
|
41
|
-
await connection.postSubjects({
|
|
42
|
-
subject: name,
|
|
43
|
-
schema,
|
|
44
|
-
});
|
|
45
|
-
} catch {
|
|
46
|
-
await connection.postSubjectsVersions({
|
|
47
|
-
subject: name,
|
|
48
|
-
schema,
|
|
49
|
-
});
|
|
50
|
-
this.log(config.name, fullName);
|
|
51
|
-
}
|
|
52
|
-
}),
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
}
|
package/src/types/sequelize.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'fs';
|
|
2
|
-
import { inject, Types } from '@biorate/inversion';
|
|
3
|
-
import { Migration } from './migration';
|
|
4
|
-
import {
|
|
5
|
-
ISequelizeConnector,
|
|
6
|
-
ISequelizeConfig,
|
|
7
|
-
ISequelizeConnection,
|
|
8
|
-
DataType,
|
|
9
|
-
Transaction,
|
|
10
|
-
} from '@biorate/sequelize';
|
|
11
|
-
/**
|
|
12
|
-
* @description Sequelize migration class
|
|
13
|
-
*/
|
|
14
|
-
export class Sequelize extends Migration {
|
|
15
|
-
@inject(Types.Sequelize) protected connector: ISequelizeConnector;
|
|
16
|
-
/**
|
|
17
|
-
* @description Sequelize process method realization
|
|
18
|
-
*/
|
|
19
|
-
protected async process() {
|
|
20
|
-
await this.forEach<ISequelizeConfig, ISequelizeConnection>(
|
|
21
|
-
'Sequelize',
|
|
22
|
-
async (config, connection, paths) => {
|
|
23
|
-
const model = connection.define(
|
|
24
|
-
this.config.get<string>('migrations.tableName', 'migrations'),
|
|
25
|
-
{
|
|
26
|
-
name: {
|
|
27
|
-
type: DataType.CHAR,
|
|
28
|
-
primaryKey: true,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
{ timestamps: false },
|
|
32
|
-
);
|
|
33
|
-
await model.sync({});
|
|
34
|
-
await this.forEachPath(
|
|
35
|
-
paths,
|
|
36
|
-
async (file, name) =>
|
|
37
|
-
await connection.transaction(async (transaction: Transaction) => {
|
|
38
|
-
const item = await model.findOne({ where: { name }, transaction });
|
|
39
|
-
if (item) return;
|
|
40
|
-
await connection.query(await fs.readFile(file, 'utf8'), { transaction });
|
|
41
|
-
await model.create({ name }, { transaction });
|
|
42
|
-
this.log(config.name, name);
|
|
43
|
-
}),
|
|
44
|
-
);
|
|
45
|
-
},
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
}
|
package/tsconfig.build.json
DELETED