UNPKG

3.68 kBTypeScriptView Raw
1import type { SetRequired } from 'type-fest';
2import type { UmzugStorage } from './contract';
3type ModelTempInterface = {} & ModelClass & Record<string, any>;
4/**
5 * Minimal structure of a sequelize model, defined here to avoid a hard dependency.
6 * The type expected is `import { Model } from 'sequelize'`
7 */
8export type ModelClass = {
9 tableName: string;
10 sequelize?: SequelizeType;
11 getTableName(): string;
12 sync(): Promise<void>;
13 findAll(options?: {}): Promise<any[]>;
14 create(options: {}): Promise<void>;
15 destroy(options: {}): Promise<void>;
16};
17/**
18 * Minimal structure of a sequelize model, defined here to avoid a hard dependency.
19 * The type expected is `import { Sequelize } from 'sequelize'`
20 */
21export type SequelizeType = {
22 getQueryInterface(): any;
23 isDefined(modelName: string): boolean;
24 model(modelName: string): any;
25 define(modelName: string, columns: {}, options: {}): {};
26 dialect?: {
27 name?: string;
28 };
29};
30type ModelClassType = ModelClass & (new (values?: object, options?: any) => ModelTempInterface);
31type _SequelizeStorageConstructorOptions = {
32 /**
33 The configured instance of Sequelize. If omitted, it is inferred from the `model` option.
34 */
35 readonly sequelize?: SequelizeType;
36 /**
37 The model representing the SequelizeMeta table. Must have a column that matches the `columnName` option. If omitted, it is created automatically.
38 */
39 readonly model?: any;
40 /**
41 The name of the model.
42
43 @default 'SequelizeMeta'
44 */
45 readonly modelName?: string;
46 /**
47 The name of the table. If omitted, defaults to the model name.
48 */
49 readonly tableName?: string;
50 /**
51 Name of the schema under which the table is to be created.
52
53 @default undefined
54 */
55 readonly schema?: any;
56 /**
57 Name of the table column holding the executed migration names.
58
59 @default 'name'
60 */
61 readonly columnName?: string;
62 /**
63 The type of the column holding the executed migration names.
64
65 For `utf8mb4` charsets under InnoDB, you may need to set this to less than 190
66
67 @default Sequelize.DataTypes.STRING
68 */
69 readonly columnType?: any;
70 /**
71 Option to add timestamps to the table
72
73 @default false
74 */
75 readonly timestamps?: boolean;
76};
77export type SequelizeStorageConstructorOptions = SetRequired<_SequelizeStorageConstructorOptions, 'sequelize'> | SetRequired<_SequelizeStorageConstructorOptions, 'model'>;
78export declare class SequelizeStorage implements UmzugStorage {
79 readonly sequelize: SequelizeType;
80 readonly columnType: string;
81 readonly columnName: string;
82 readonly timestamps: boolean;
83 readonly modelName: string;
84 readonly tableName?: string;
85 readonly schema: any;
86 readonly model: ModelClassType;
87 /**
88 Constructs Sequelize based storage. Migrations will be stored in a SequelizeMeta table using the given instance of Sequelize.
89
90 If a model is given, it will be used directly as the model for the SequelizeMeta table. Otherwise, it will be created automatically according to the given options.
91
92 If the table does not exist it will be created automatically upon the logging of the first migration.
93 */
94 constructor(options: SequelizeStorageConstructorOptions);
95 getModel(): ModelClassType;
96 protected syncModel(): Promise<void>;
97 logMigration({ name: migrationName }: {
98 name: string;
99 }): Promise<void>;
100 unlogMigration({ name: migrationName }: {
101 name: string;
102 }): Promise<void>;
103 executed(): Promise<string[]>;
104 _model(): ModelClassType;
105}
106export {};
107
\No newline at end of file