@famgia/omnify-sql 0.0.2
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/README.md +201 -0
- package/dist/chunk-V7HEGSN4.js +1118 -0
- package/dist/chunk-V7HEGSN4.js.map +1 -0
- package/dist/chunk-YNWO77KO.cjs +1118 -0
- package/dist/chunk-YNWO77KO.cjs.map +1 -0
- package/dist/index.cjs +47 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +137 -0
- package/dist/index.d.ts +137 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.cjs +55 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.d.cts +68 -0
- package/dist/plugin.d.ts +68 -0
- package/dist/plugin.js +55 -0
- package/dist/plugin.js.map +1 -0
- package/dist/types-DkJkHX8d.d.cts +127 -0
- package/dist/types-DkJkHX8d.d.ts +127 -0
- package/package.json +66 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { OmnifyPlugin } from '@famgia/omnify-types';
|
|
2
|
+
import { c as SqlDialect } from './types-DkJkHX8d.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @famgia/omnify-sql - Plugin
|
|
6
|
+
*
|
|
7
|
+
* Plugin wrapper for SQL migration generator.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { defineConfig } from '@famgia/omnify';
|
|
12
|
+
* import sql from '@famgia/omnify-sql/plugin';
|
|
13
|
+
*
|
|
14
|
+
* export default defineConfig({
|
|
15
|
+
* plugins: [
|
|
16
|
+
* sql({
|
|
17
|
+
* dialect: 'postgresql',
|
|
18
|
+
* migrationsPath: 'migrations',
|
|
19
|
+
* }),
|
|
20
|
+
* ],
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Options for the SQL plugin.
|
|
27
|
+
*/
|
|
28
|
+
interface SqlPluginOptions {
|
|
29
|
+
/**
|
|
30
|
+
* SQL dialect to generate.
|
|
31
|
+
* @default 'mysql'
|
|
32
|
+
*/
|
|
33
|
+
dialect?: SqlDialect;
|
|
34
|
+
/**
|
|
35
|
+
* Path for SQL migration files.
|
|
36
|
+
* @default 'migrations'
|
|
37
|
+
*/
|
|
38
|
+
migrationsPath?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Use IF NOT EXISTS in CREATE TABLE.
|
|
41
|
+
* @default true
|
|
42
|
+
*/
|
|
43
|
+
ifNotExists?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Include commented DROP TABLE in migrations.
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
generateDown?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Starting version number.
|
|
51
|
+
* @default 1
|
|
52
|
+
*/
|
|
53
|
+
startVersion?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Version number padding (e.g., 4 for 0001).
|
|
56
|
+
* @default 4
|
|
57
|
+
*/
|
|
58
|
+
versionPadding?: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates the SQL plugin with the specified options.
|
|
62
|
+
*
|
|
63
|
+
* @param options - Plugin configuration options
|
|
64
|
+
* @returns OmnifyPlugin configured for SQL
|
|
65
|
+
*/
|
|
66
|
+
declare function sqlPlugin(options?: SqlPluginOptions): OmnifyPlugin;
|
|
67
|
+
|
|
68
|
+
export { type SqlPluginOptions, sqlPlugin as default, sqlPlugin };
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { OmnifyPlugin } from '@famgia/omnify-types';
|
|
2
|
+
import { c as SqlDialect } from './types-DkJkHX8d.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @famgia/omnify-sql - Plugin
|
|
6
|
+
*
|
|
7
|
+
* Plugin wrapper for SQL migration generator.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { defineConfig } from '@famgia/omnify';
|
|
12
|
+
* import sql from '@famgia/omnify-sql/plugin';
|
|
13
|
+
*
|
|
14
|
+
* export default defineConfig({
|
|
15
|
+
* plugins: [
|
|
16
|
+
* sql({
|
|
17
|
+
* dialect: 'postgresql',
|
|
18
|
+
* migrationsPath: 'migrations',
|
|
19
|
+
* }),
|
|
20
|
+
* ],
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Options for the SQL plugin.
|
|
27
|
+
*/
|
|
28
|
+
interface SqlPluginOptions {
|
|
29
|
+
/**
|
|
30
|
+
* SQL dialect to generate.
|
|
31
|
+
* @default 'mysql'
|
|
32
|
+
*/
|
|
33
|
+
dialect?: SqlDialect;
|
|
34
|
+
/**
|
|
35
|
+
* Path for SQL migration files.
|
|
36
|
+
* @default 'migrations'
|
|
37
|
+
*/
|
|
38
|
+
migrationsPath?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Use IF NOT EXISTS in CREATE TABLE.
|
|
41
|
+
* @default true
|
|
42
|
+
*/
|
|
43
|
+
ifNotExists?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Include commented DROP TABLE in migrations.
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
generateDown?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Starting version number.
|
|
51
|
+
* @default 1
|
|
52
|
+
*/
|
|
53
|
+
startVersion?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Version number padding (e.g., 4 for 0001).
|
|
56
|
+
* @default 4
|
|
57
|
+
*/
|
|
58
|
+
versionPadding?: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates the SQL plugin with the specified options.
|
|
62
|
+
*
|
|
63
|
+
* @param options - Plugin configuration options
|
|
64
|
+
* @returns OmnifyPlugin configured for SQL
|
|
65
|
+
*/
|
|
66
|
+
declare function sqlPlugin(options?: SqlPluginOptions): OmnifyPlugin;
|
|
67
|
+
|
|
68
|
+
export { type SqlPluginOptions, sqlPlugin as default, sqlPlugin };
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateMigrations,
|
|
3
|
+
getMigrationPath
|
|
4
|
+
} from "./chunk-V7HEGSN4.js";
|
|
5
|
+
|
|
6
|
+
// src/plugin.ts
|
|
7
|
+
function resolveOptions(options) {
|
|
8
|
+
return {
|
|
9
|
+
dialect: options?.dialect ?? "mysql",
|
|
10
|
+
migrationsPath: options?.migrationsPath ?? "migrations",
|
|
11
|
+
ifNotExists: options?.ifNotExists ?? true,
|
|
12
|
+
generateDown: options?.generateDown ?? true,
|
|
13
|
+
startVersion: options?.startVersion ?? 1,
|
|
14
|
+
versionPadding: options?.versionPadding ?? 4
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function sqlPlugin(options) {
|
|
18
|
+
const resolved = resolveOptions(options);
|
|
19
|
+
return {
|
|
20
|
+
name: "@famgia/omnify-sql",
|
|
21
|
+
version: "0.0.1",
|
|
22
|
+
generators: [
|
|
23
|
+
{
|
|
24
|
+
name: "sql-migrations",
|
|
25
|
+
description: `Generate ${resolved.dialect.toUpperCase()} SQL migration files`,
|
|
26
|
+
generate: async (ctx) => {
|
|
27
|
+
const generatorOptions = {
|
|
28
|
+
dialect: resolved.dialect,
|
|
29
|
+
ifNotExists: resolved.ifNotExists,
|
|
30
|
+
generateDown: resolved.generateDown,
|
|
31
|
+
startVersion: resolved.startVersion,
|
|
32
|
+
versionPadding: resolved.versionPadding
|
|
33
|
+
};
|
|
34
|
+
const migrations = generateMigrations(ctx.schemas, generatorOptions);
|
|
35
|
+
return migrations.map((migration) => ({
|
|
36
|
+
path: getMigrationPath(migration, resolved.migrationsPath),
|
|
37
|
+
content: migration.content,
|
|
38
|
+
type: "migration",
|
|
39
|
+
metadata: {
|
|
40
|
+
version: migration.version,
|
|
41
|
+
tables: migration.tables,
|
|
42
|
+
migrationType: migration.type,
|
|
43
|
+
dialect: resolved.dialect
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
sqlPlugin as default,
|
|
53
|
+
sqlPlugin
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["/**\n * @famgia/omnify-sql - Plugin\n *\n * Plugin wrapper for SQL migration generator.\n *\n * @example\n * ```typescript\n * import { defineConfig } from '@famgia/omnify';\n * import sql from '@famgia/omnify-sql/plugin';\n *\n * export default defineConfig({\n * plugins: [\n * sql({\n * dialect: 'postgresql',\n * migrationsPath: 'migrations',\n * }),\n * ],\n * });\n * ```\n */\n\nimport type { OmnifyPlugin, GeneratorOutput, GeneratorContext } from '@famgia/omnify-types';\nimport type { SqlDialect, SqlGeneratorOptions } from './types.js';\nimport { generateMigrations, getMigrationPath } from './migration/index.js';\n\n/**\n * Options for the SQL plugin.\n */\nexport interface SqlPluginOptions {\n /**\n * SQL dialect to generate.\n * @default 'mysql'\n */\n dialect?: SqlDialect;\n\n /**\n * Path for SQL migration files.\n * @default 'migrations'\n */\n migrationsPath?: string;\n\n /**\n * Use IF NOT EXISTS in CREATE TABLE.\n * @default true\n */\n ifNotExists?: boolean;\n\n /**\n * Include commented DROP TABLE in migrations.\n * @default true\n */\n generateDown?: boolean;\n\n /**\n * Starting version number.\n * @default 1\n */\n startVersion?: number;\n\n /**\n * Version number padding (e.g., 4 for 0001).\n * @default 4\n */\n versionPadding?: number;\n}\n\n/**\n * Resolved options with defaults.\n */\ninterface ResolvedPluginOptions {\n dialect: SqlDialect;\n migrationsPath: string;\n ifNotExists: boolean;\n generateDown: boolean;\n startVersion: number;\n versionPadding: number;\n}\n\n/**\n * Resolves options with defaults.\n */\nfunction resolveOptions(options?: SqlPluginOptions): ResolvedPluginOptions {\n return {\n dialect: options?.dialect ?? 'mysql',\n migrationsPath: options?.migrationsPath ?? 'migrations',\n ifNotExists: options?.ifNotExists ?? true,\n generateDown: options?.generateDown ?? true,\n startVersion: options?.startVersion ?? 1,\n versionPadding: options?.versionPadding ?? 4,\n };\n}\n\n/**\n * Creates the SQL plugin with the specified options.\n *\n * @param options - Plugin configuration options\n * @returns OmnifyPlugin configured for SQL\n */\nexport default function sqlPlugin(options?: SqlPluginOptions): OmnifyPlugin {\n const resolved = resolveOptions(options);\n\n return {\n name: '@famgia/omnify-sql',\n version: '0.0.1',\n\n generators: [\n {\n name: 'sql-migrations',\n description: `Generate ${resolved.dialect.toUpperCase()} SQL migration files`,\n\n generate: async (ctx: GeneratorContext): Promise<GeneratorOutput[]> => {\n const generatorOptions: SqlGeneratorOptions = {\n dialect: resolved.dialect,\n ifNotExists: resolved.ifNotExists,\n generateDown: resolved.generateDown,\n startVersion: resolved.startVersion,\n versionPadding: resolved.versionPadding,\n };\n\n const migrations = generateMigrations(ctx.schemas, generatorOptions);\n\n return migrations.map((migration) => ({\n path: getMigrationPath(migration, resolved.migrationsPath),\n content: migration.content,\n type: 'migration' as const,\n metadata: {\n version: migration.version,\n tables: migration.tables,\n migrationType: migration.type,\n dialect: resolved.dialect,\n },\n }));\n },\n },\n ],\n };\n}\n\n// Named export for flexibility\nexport { sqlPlugin };\n"],"mappings":";;;;;;AAiFA,SAAS,eAAe,SAAmD;AACzE,SAAO;AAAA,IACL,SAAS,SAAS,WAAW;AAAA,IAC7B,gBAAgB,SAAS,kBAAkB;AAAA,IAC3C,aAAa,SAAS,eAAe;AAAA,IACrC,cAAc,SAAS,gBAAgB;AAAA,IACvC,cAAc,SAAS,gBAAgB;AAAA,IACvC,gBAAgB,SAAS,kBAAkB;AAAA,EAC7C;AACF;AAQe,SAAR,UAA2B,SAA0C;AAC1E,QAAM,WAAW,eAAe,OAAO;AAEvC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,YAAY;AAAA,MACV;AAAA,QACE,MAAM;AAAA,QACN,aAAa,YAAY,SAAS,QAAQ,YAAY,CAAC;AAAA,QAEvD,UAAU,OAAO,QAAsD;AACrE,gBAAM,mBAAwC;AAAA,YAC5C,SAAS,SAAS;AAAA,YAClB,aAAa,SAAS;AAAA,YACtB,cAAc,SAAS;AAAA,YACvB,cAAc,SAAS;AAAA,YACvB,gBAAgB,SAAS;AAAA,UAC3B;AAEA,gBAAM,aAAa,mBAAmB,IAAI,SAAS,gBAAgB;AAEnE,iBAAO,WAAW,IAAI,CAAC,eAAe;AAAA,YACpC,MAAM,iBAAiB,WAAW,SAAS,cAAc;AAAA,YACzD,SAAS,UAAU;AAAA,YACnB,MAAM;AAAA,YACN,UAAU;AAAA,cACR,SAAS,UAAU;AAAA,cACnB,QAAQ,UAAU;AAAA,cAClB,eAAe,UAAU;AAAA,cACzB,SAAS,SAAS;AAAA,YACpB;AAAA,UACF,EAAE;AAAA,QACJ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @famgia/omnify-sql - Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for SQL migration generator.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Supported SQL dialects.
|
|
8
|
+
*/
|
|
9
|
+
type SqlDialect = 'mysql' | 'postgresql' | 'sqlite';
|
|
10
|
+
/**
|
|
11
|
+
* SQL migration file.
|
|
12
|
+
*/
|
|
13
|
+
interface SqlMigration {
|
|
14
|
+
/** Migration version number (e.g., 1, 2, 3) */
|
|
15
|
+
readonly version: number;
|
|
16
|
+
/** Migration name (e.g., 'create_users') */
|
|
17
|
+
readonly name: string;
|
|
18
|
+
/** Full file name (e.g., '0001_create_users.sql') */
|
|
19
|
+
readonly fileName: string;
|
|
20
|
+
/** SQL content */
|
|
21
|
+
readonly content: string;
|
|
22
|
+
/** Tables affected */
|
|
23
|
+
readonly tables: readonly string[];
|
|
24
|
+
/** Migration type */
|
|
25
|
+
readonly type: 'create' | 'alter' | 'drop' | 'pivot';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* SQL column definition.
|
|
29
|
+
*/
|
|
30
|
+
interface SqlColumn {
|
|
31
|
+
/** Column name */
|
|
32
|
+
readonly name: string;
|
|
33
|
+
/** SQL type (e.g., 'VARCHAR(255)', 'BIGINT') */
|
|
34
|
+
readonly type: string;
|
|
35
|
+
/** Is nullable */
|
|
36
|
+
readonly nullable: boolean;
|
|
37
|
+
/** Default value */
|
|
38
|
+
readonly defaultValue?: string | undefined;
|
|
39
|
+
/** Is primary key */
|
|
40
|
+
readonly primaryKey: boolean;
|
|
41
|
+
/** Is auto increment */
|
|
42
|
+
readonly autoIncrement: boolean;
|
|
43
|
+
/** Is unique */
|
|
44
|
+
readonly unique: boolean;
|
|
45
|
+
/** Is unsigned (MySQL) */
|
|
46
|
+
readonly unsigned: boolean;
|
|
47
|
+
/** Column comment */
|
|
48
|
+
readonly comment?: string | undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* SQL foreign key definition.
|
|
52
|
+
*/
|
|
53
|
+
interface SqlForeignKey {
|
|
54
|
+
/** Constraint name */
|
|
55
|
+
readonly name: string;
|
|
56
|
+
/** Local column(s) */
|
|
57
|
+
readonly columns: readonly string[];
|
|
58
|
+
/** Referenced table */
|
|
59
|
+
readonly referencesTable: string;
|
|
60
|
+
/** Referenced column(s) */
|
|
61
|
+
readonly referencesColumns: readonly string[];
|
|
62
|
+
/** ON DELETE action */
|
|
63
|
+
readonly onDelete: string;
|
|
64
|
+
/** ON UPDATE action */
|
|
65
|
+
readonly onUpdate: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* SQL index type.
|
|
69
|
+
*/
|
|
70
|
+
type SqlIndexType = 'btree' | 'hash' | 'fulltext' | 'spatial' | 'gin' | 'gist';
|
|
71
|
+
/**
|
|
72
|
+
* SQL index definition.
|
|
73
|
+
*/
|
|
74
|
+
interface SqlIndex {
|
|
75
|
+
/** Index name */
|
|
76
|
+
readonly name: string;
|
|
77
|
+
/** Columns in the index */
|
|
78
|
+
readonly columns: readonly string[];
|
|
79
|
+
/** Is unique index */
|
|
80
|
+
readonly unique: boolean;
|
|
81
|
+
/** Index type (fulltext, spatial, etc.) */
|
|
82
|
+
readonly type?: SqlIndexType | undefined;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* SQL table definition.
|
|
86
|
+
*/
|
|
87
|
+
interface SqlTable {
|
|
88
|
+
/** Table name */
|
|
89
|
+
readonly name: string;
|
|
90
|
+
/** Columns */
|
|
91
|
+
readonly columns: readonly SqlColumn[];
|
|
92
|
+
/** Foreign keys */
|
|
93
|
+
readonly foreignKeys: readonly SqlForeignKey[];
|
|
94
|
+
/** Indexes */
|
|
95
|
+
readonly indexes: readonly SqlIndex[];
|
|
96
|
+
/** Table comment */
|
|
97
|
+
readonly comment?: string | undefined;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Options for SQL generation.
|
|
101
|
+
*/
|
|
102
|
+
interface SqlGeneratorOptions {
|
|
103
|
+
/** SQL dialect */
|
|
104
|
+
readonly dialect?: SqlDialect;
|
|
105
|
+
/** Use IF NOT EXISTS for CREATE TABLE */
|
|
106
|
+
readonly ifNotExists?: boolean;
|
|
107
|
+
/** Add DROP TABLE statements in down migration */
|
|
108
|
+
readonly generateDown?: boolean;
|
|
109
|
+
/** Starting version number */
|
|
110
|
+
readonly startVersion?: number;
|
|
111
|
+
/** Version number padding (e.g., 4 for 0001) */
|
|
112
|
+
readonly versionPadding?: number;
|
|
113
|
+
/** Custom timestamp for file names */
|
|
114
|
+
readonly timestamp?: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Resolved options with defaults.
|
|
118
|
+
*/
|
|
119
|
+
interface ResolvedSqlOptions {
|
|
120
|
+
readonly dialect: SqlDialect;
|
|
121
|
+
readonly ifNotExists: boolean;
|
|
122
|
+
readonly generateDown: boolean;
|
|
123
|
+
readonly startVersion: number;
|
|
124
|
+
readonly versionPadding: number;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export type { ResolvedSqlOptions as R, SqlGeneratorOptions as S, SqlMigration as a, SqlTable as b, SqlDialect as c, SqlColumn as d, SqlForeignKey as e, SqlIndex as f, SqlIndexType as g };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @famgia/omnify-sql - Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for SQL migration generator.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Supported SQL dialects.
|
|
8
|
+
*/
|
|
9
|
+
type SqlDialect = 'mysql' | 'postgresql' | 'sqlite';
|
|
10
|
+
/**
|
|
11
|
+
* SQL migration file.
|
|
12
|
+
*/
|
|
13
|
+
interface SqlMigration {
|
|
14
|
+
/** Migration version number (e.g., 1, 2, 3) */
|
|
15
|
+
readonly version: number;
|
|
16
|
+
/** Migration name (e.g., 'create_users') */
|
|
17
|
+
readonly name: string;
|
|
18
|
+
/** Full file name (e.g., '0001_create_users.sql') */
|
|
19
|
+
readonly fileName: string;
|
|
20
|
+
/** SQL content */
|
|
21
|
+
readonly content: string;
|
|
22
|
+
/** Tables affected */
|
|
23
|
+
readonly tables: readonly string[];
|
|
24
|
+
/** Migration type */
|
|
25
|
+
readonly type: 'create' | 'alter' | 'drop' | 'pivot';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* SQL column definition.
|
|
29
|
+
*/
|
|
30
|
+
interface SqlColumn {
|
|
31
|
+
/** Column name */
|
|
32
|
+
readonly name: string;
|
|
33
|
+
/** SQL type (e.g., 'VARCHAR(255)', 'BIGINT') */
|
|
34
|
+
readonly type: string;
|
|
35
|
+
/** Is nullable */
|
|
36
|
+
readonly nullable: boolean;
|
|
37
|
+
/** Default value */
|
|
38
|
+
readonly defaultValue?: string | undefined;
|
|
39
|
+
/** Is primary key */
|
|
40
|
+
readonly primaryKey: boolean;
|
|
41
|
+
/** Is auto increment */
|
|
42
|
+
readonly autoIncrement: boolean;
|
|
43
|
+
/** Is unique */
|
|
44
|
+
readonly unique: boolean;
|
|
45
|
+
/** Is unsigned (MySQL) */
|
|
46
|
+
readonly unsigned: boolean;
|
|
47
|
+
/** Column comment */
|
|
48
|
+
readonly comment?: string | undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* SQL foreign key definition.
|
|
52
|
+
*/
|
|
53
|
+
interface SqlForeignKey {
|
|
54
|
+
/** Constraint name */
|
|
55
|
+
readonly name: string;
|
|
56
|
+
/** Local column(s) */
|
|
57
|
+
readonly columns: readonly string[];
|
|
58
|
+
/** Referenced table */
|
|
59
|
+
readonly referencesTable: string;
|
|
60
|
+
/** Referenced column(s) */
|
|
61
|
+
readonly referencesColumns: readonly string[];
|
|
62
|
+
/** ON DELETE action */
|
|
63
|
+
readonly onDelete: string;
|
|
64
|
+
/** ON UPDATE action */
|
|
65
|
+
readonly onUpdate: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* SQL index type.
|
|
69
|
+
*/
|
|
70
|
+
type SqlIndexType = 'btree' | 'hash' | 'fulltext' | 'spatial' | 'gin' | 'gist';
|
|
71
|
+
/**
|
|
72
|
+
* SQL index definition.
|
|
73
|
+
*/
|
|
74
|
+
interface SqlIndex {
|
|
75
|
+
/** Index name */
|
|
76
|
+
readonly name: string;
|
|
77
|
+
/** Columns in the index */
|
|
78
|
+
readonly columns: readonly string[];
|
|
79
|
+
/** Is unique index */
|
|
80
|
+
readonly unique: boolean;
|
|
81
|
+
/** Index type (fulltext, spatial, etc.) */
|
|
82
|
+
readonly type?: SqlIndexType | undefined;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* SQL table definition.
|
|
86
|
+
*/
|
|
87
|
+
interface SqlTable {
|
|
88
|
+
/** Table name */
|
|
89
|
+
readonly name: string;
|
|
90
|
+
/** Columns */
|
|
91
|
+
readonly columns: readonly SqlColumn[];
|
|
92
|
+
/** Foreign keys */
|
|
93
|
+
readonly foreignKeys: readonly SqlForeignKey[];
|
|
94
|
+
/** Indexes */
|
|
95
|
+
readonly indexes: readonly SqlIndex[];
|
|
96
|
+
/** Table comment */
|
|
97
|
+
readonly comment?: string | undefined;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Options for SQL generation.
|
|
101
|
+
*/
|
|
102
|
+
interface SqlGeneratorOptions {
|
|
103
|
+
/** SQL dialect */
|
|
104
|
+
readonly dialect?: SqlDialect;
|
|
105
|
+
/** Use IF NOT EXISTS for CREATE TABLE */
|
|
106
|
+
readonly ifNotExists?: boolean;
|
|
107
|
+
/** Add DROP TABLE statements in down migration */
|
|
108
|
+
readonly generateDown?: boolean;
|
|
109
|
+
/** Starting version number */
|
|
110
|
+
readonly startVersion?: number;
|
|
111
|
+
/** Version number padding (e.g., 4 for 0001) */
|
|
112
|
+
readonly versionPadding?: number;
|
|
113
|
+
/** Custom timestamp for file names */
|
|
114
|
+
readonly timestamp?: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Resolved options with defaults.
|
|
118
|
+
*/
|
|
119
|
+
interface ResolvedSqlOptions {
|
|
120
|
+
readonly dialect: SqlDialect;
|
|
121
|
+
readonly ifNotExists: boolean;
|
|
122
|
+
readonly generateDown: boolean;
|
|
123
|
+
readonly startVersion: number;
|
|
124
|
+
readonly versionPadding: number;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export type { ResolvedSqlOptions as R, SqlGeneratorOptions as S, SqlMigration as a, SqlTable as b, SqlDialect as c, SqlColumn as d, SqlForeignKey as e, SqlIndex as f, SqlIndexType as g };
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@famgia/omnify-sql",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Raw SQL migration generator for Omnify Schema",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./plugin": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/plugin.d.ts",
|
|
23
|
+
"default": "./dist/plugin.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/plugin.d.cts",
|
|
27
|
+
"default": "./dist/plugin.cjs"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@famgia/omnify-types": "0.0.8"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"tsup": "^8.5.1",
|
|
39
|
+
"typescript": "^5.8.3",
|
|
40
|
+
"vitest": "^1.6.1",
|
|
41
|
+
"@famgia/omnify-core": "0.0.8"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@famgia/omnify-core": ">=0.0.7"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"omnify",
|
|
48
|
+
"sql",
|
|
49
|
+
"migrations",
|
|
50
|
+
"database",
|
|
51
|
+
"schema"
|
|
52
|
+
],
|
|
53
|
+
"author": "Famgia",
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "https://github.com/famgia/omnify-ts.git",
|
|
58
|
+
"directory": "packages/sql-generator"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "tsup",
|
|
62
|
+
"dev": "tsup --watch",
|
|
63
|
+
"test": "vitest run --passWithNoTests",
|
|
64
|
+
"clean": "rm -rf dist"
|
|
65
|
+
}
|
|
66
|
+
}
|