sonamu 0.5.7 → 0.7.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/.swcrc.project-default +18 -0
- package/bin/cli.js +24 -0
- package/dist/ai/agents/agent.d.ts +11 -0
- package/dist/ai/agents/agent.d.ts.map +1 -0
- package/dist/ai/agents/agent.js +65 -0
- package/dist/ai/agents/index.d.ts +3 -0
- package/dist/ai/agents/index.d.ts.map +1 -0
- package/dist/ai/agents/index.js +4 -0
- package/dist/ai/agents/types.d.ts +43 -0
- package/dist/ai/agents/types.d.ts.map +1 -0
- package/dist/ai/agents/types.js +3 -0
- package/dist/ai/index.d.ts +2 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +3 -0
- package/dist/ai/providers/rtzr/api.d.ts +22 -0
- package/dist/ai/providers/rtzr/api.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/api.js +28 -0
- package/dist/ai/providers/rtzr/error.d.ts +18 -0
- package/dist/ai/providers/rtzr/error.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/error.js +29 -0
- package/dist/ai/providers/rtzr/index.d.ts +5 -0
- package/dist/ai/providers/rtzr/index.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/index.js +6 -0
- package/dist/ai/providers/rtzr/model.d.ts +52 -0
- package/dist/ai/providers/rtzr/model.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/model.js +137 -0
- package/dist/ai/providers/rtzr/options.d.ts +7 -0
- package/dist/ai/providers/rtzr/options.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/options.js +47 -0
- package/dist/ai/providers/rtzr/provider.d.ts +18 -0
- package/dist/ai/providers/rtzr/provider.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/provider.js +54 -0
- package/dist/ai/providers/rtzr/utils.d.ts +19 -0
- package/dist/ai/providers/rtzr/utils.d.ts.map +1 -0
- package/dist/ai/providers/rtzr/utils.js +88 -0
- package/dist/api/base-frame.d.ts +2 -2
- package/dist/api/base-frame.d.ts.map +1 -1
- package/dist/api/base-frame.js +13 -2
- package/dist/api/caster.d.ts.map +1 -1
- package/dist/api/caster.js +71 -2
- package/dist/api/code-converters.d.ts +58 -14
- package/dist/api/code-converters.d.ts.map +1 -1
- package/dist/api/code-converters.js +258 -2
- package/dist/api/config.d.ts +90 -0
- package/dist/api/config.d.ts.map +1 -0
- package/dist/api/config.js +25 -0
- package/dist/api/context.d.ts +4 -2
- package/dist/api/context.d.ts.map +1 -1
- package/dist/api/context.js +3 -2
- package/dist/api/decorators.d.ts +20 -6
- package/dist/api/decorators.d.ts.map +1 -1
- package/dist/api/decorators.js +235 -2
- package/dist/api/index.d.ts +2 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +9 -2
- package/dist/api/sonamu.d.ts +10 -24
- package/dist/api/sonamu.d.ts.map +1 -1
- package/dist/api/sonamu.js +514 -2
- package/dist/api/validator.d.ts +6 -0
- package/dist/api/validator.d.ts.map +1 -0
- package/dist/api/validator.js +81 -0
- package/dist/bin/build-config.d.ts +6 -1
- package/dist/bin/build-config.d.ts.map +1 -1
- package/dist/bin/build-config.js +15 -2
- package/dist/bin/cli.js +519 -2
- package/dist/bin/hot-hook-register.d.ts +11 -0
- package/dist/bin/hot-hook-register.d.ts.map +1 -0
- package/dist/bin/hot-hook-register.js +21 -0
- package/dist/bin/loader-register.d.ts +2 -0
- package/dist/bin/loader-register.d.ts.map +1 -0
- package/dist/bin/loader-register.js +34 -0
- package/dist/database/_batch_update.d.ts +5 -3
- package/dist/database/_batch_update.d.ts.map +1 -1
- package/dist/database/_batch_update.js +95 -2
- package/dist/database/base-model.d.ts +96 -10
- package/dist/database/base-model.d.ts.map +1 -1
- package/dist/database/base-model.js +390 -2
- package/dist/database/base-model.types.d.ts +93 -0
- package/dist/database/base-model.types.d.ts.map +1 -0
- package/dist/database/base-model.types.js +10 -0
- package/dist/database/code-generator.d.ts +1 -1
- package/dist/database/code-generator.d.ts.map +1 -1
- package/dist/database/code-generator.js +54 -2
- package/dist/database/db.d.ts +6 -21
- package/dist/database/db.d.ts.map +1 -1
- package/dist/database/db.js +129 -2
- package/dist/database/puri-subset.test-d.js +81 -0
- package/dist/database/puri-subset.types.d.ts +123 -0
- package/dist/database/puri-subset.types.d.ts.map +1 -0
- package/dist/database/puri-subset.types.js +16 -0
- package/dist/database/puri-wrapper.d.ts +13 -11
- package/dist/database/puri-wrapper.d.ts.map +1 -1
- package/dist/database/puri-wrapper.js +109 -2
- package/dist/database/puri.d.ts +41 -23
- package/dist/database/puri.d.ts.map +1 -1
- package/dist/database/puri.js +601 -2
- package/dist/database/puri.types.d.ts +25 -6
- package/dist/database/puri.types.d.ts.map +1 -1
- package/dist/database/puri.types.js +6 -2
- package/dist/database/transaction-context.d.ts +1 -1
- package/dist/database/transaction-context.d.ts.map +1 -1
- package/dist/database/transaction-context.js +14 -2
- package/dist/database/upsert-builder.d.ts +9 -3
- package/dist/database/upsert-builder.d.ts.map +1 -1
- package/dist/database/upsert-builder.js +365 -2
- package/dist/entity/entity-manager.d.ts +167 -2
- package/dist/entity/entity-manager.d.ts.map +1 -1
- package/dist/entity/entity-manager.js +130 -2
- package/dist/entity/entity.d.ts +5 -3
- package/dist/entity/entity.d.ts.map +1 -1
- package/dist/entity/entity.js +750 -2
- package/dist/exceptions/error-handler.d.ts +1 -1
- package/dist/exceptions/error-handler.d.ts.map +1 -1
- package/dist/exceptions/error-handler.js +29 -2
- package/dist/exceptions/so-exceptions.d.ts +1 -1
- package/dist/exceptions/so-exceptions.d.ts.map +1 -1
- package/dist/exceptions/so-exceptions.js +85 -2
- package/dist/file-storage/driver.d.ts +1 -1
- package/dist/file-storage/driver.d.ts.map +1 -1
- package/dist/file-storage/driver.js +79 -2
- package/dist/file-storage/file-storage.js +75 -2
- package/dist/index.d.ts +18 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -2
- package/dist/migration/code-generation.d.ts +1 -1
- package/dist/migration/code-generation.d.ts.map +1 -1
- package/dist/migration/code-generation.js +614 -2
- package/dist/migration/migration-set.d.ts +2 -10
- package/dist/migration/migration-set.d.ts.map +1 -1
- package/dist/migration/migration-set.js +213 -2
- package/dist/migration/migrator.d.ts +24 -82
- package/dist/migration/migrator.d.ts.map +1 -1
- package/dist/migration/migrator.js +330 -2
- package/dist/migration/postgresql-schema-reader.d.ts +51 -0
- package/dist/migration/postgresql-schema-reader.d.ts.map +1 -0
- package/dist/migration/postgresql-schema-reader.js +245 -0
- package/dist/migration/types.d.ts +6 -38
- package/dist/migration/types.d.ts.map +1 -1
- package/dist/migration/types.js +3 -2
- package/dist/naite/messaging-types.d.ts +43 -0
- package/dist/naite/messaging-types.d.ts.map +1 -0
- package/dist/naite/messaging-types.js +7 -0
- package/dist/naite/naite-reporter.d.ts +41 -0
- package/dist/naite/naite-reporter.d.ts.map +1 -0
- package/dist/naite/naite-reporter.js +102 -0
- package/dist/naite/naite.d.ts +95 -0
- package/dist/naite/naite.d.ts.map +1 -0
- package/dist/naite/naite.js +316 -0
- package/dist/stream/index.js +3 -2
- package/dist/stream/sse.d.ts +2 -2
- package/dist/stream/sse.d.ts.map +1 -1
- package/dist/stream/sse.js +38 -2
- package/dist/syncer/api-parser.d.ts +10 -0
- package/dist/syncer/api-parser.d.ts.map +1 -0
- package/dist/syncer/api-parser.js +240 -0
- package/dist/syncer/checksum.d.ts +21 -0
- package/dist/syncer/checksum.d.ts.map +1 -0
- package/dist/syncer/checksum.js +98 -0
- package/dist/syncer/code-generator.d.ts +20 -0
- package/dist/syncer/code-generator.d.ts.map +1 -0
- package/dist/syncer/code-generator.js +161 -0
- package/dist/syncer/entity-operations.d.ts +17 -0
- package/dist/syncer/entity-operations.d.ts.map +1 -0
- package/dist/syncer/entity-operations.js +59 -0
- package/dist/syncer/file-patterns.d.ts +29 -0
- package/dist/syncer/file-patterns.d.ts.map +1 -0
- package/dist/syncer/file-patterns.js +38 -0
- package/dist/syncer/index.d.ts +6 -0
- package/dist/syncer/index.d.ts.map +1 -1
- package/dist/syncer/index.js +9 -2
- package/dist/syncer/module-loader.d.ts +35 -0
- package/dist/syncer/module-loader.d.ts.map +1 -0
- package/dist/syncer/module-loader.js +87 -0
- package/dist/syncer/syncer.d.ts +98 -106
- package/dist/syncer/syncer.d.ts.map +1 -1
- package/dist/syncer/syncer.js +422 -2
- package/dist/template/entity-converter.d.ts +14 -0
- package/dist/template/entity-converter.d.ts.map +1 -0
- package/dist/template/entity-converter.js +108 -0
- package/dist/template/helpers.d.ts +23 -0
- package/dist/template/helpers.d.ts.map +1 -0
- package/dist/template/helpers.js +64 -0
- package/dist/{templates → template/implementations}/entity.template.d.ts +3 -3
- package/dist/template/implementations/entity.template.d.ts.map +1 -0
- package/dist/template/implementations/entity.template.js +86 -0
- package/dist/{templates → template/implementations}/generated.template.d.ts +3 -4
- package/dist/template/implementations/generated.template.d.ts.map +1 -0
- package/dist/template/implementations/generated.template.js +249 -0
- package/dist/{templates → template/implementations}/generated_http.template.d.ts +3 -4
- package/dist/template/implementations/generated_http.template.d.ts.map +1 -0
- package/dist/template/implementations/generated_http.template.js +131 -0
- package/dist/{templates → template/implementations}/generated_sso.template.d.ts +4 -5
- package/dist/template/implementations/generated_sso.template.d.ts.map +1 -0
- package/dist/template/implementations/generated_sso.template.js +134 -0
- package/dist/{templates → template/implementations}/init_types.template.d.ts +3 -3
- package/dist/template/implementations/init_types.template.d.ts.map +1 -0
- package/dist/template/implementations/init_types.template.js +38 -0
- package/dist/template/implementations/model.template.d.ts +17 -0
- package/dist/template/implementations/model.template.d.ts.map +1 -0
- package/dist/template/implementations/model.template.js +181 -0
- package/dist/{templates → template/implementations}/model_test.template.d.ts +3 -3
- package/dist/template/implementations/model_test.template.d.ts.map +1 -0
- package/dist/template/implementations/model_test.template.js +35 -0
- package/dist/{templates → template/implementations}/service.template.d.ts +6 -6
- package/dist/template/implementations/service.template.d.ts.map +1 -0
- package/dist/template/implementations/service.template.js +201 -0
- package/dist/{templates → template/implementations}/view_enums_buttonset.template.d.ts +3 -3
- package/dist/template/implementations/view_enums_buttonset.template.d.ts.map +1 -0
- package/dist/template/implementations/view_enums_buttonset.template.js +31 -0
- package/dist/{templates → template/implementations}/view_enums_dropdown.template.d.ts +3 -4
- package/dist/template/implementations/view_enums_dropdown.template.d.ts.map +1 -0
- package/dist/template/implementations/view_enums_dropdown.template.js +50 -0
- package/dist/{templates → template/implementations}/view_enums_select.template.d.ts +3 -3
- package/dist/template/implementations/view_enums_select.template.d.ts.map +1 -0
- package/dist/template/implementations/view_enums_select.template.js +55 -0
- package/dist/{templates → template/implementations}/view_form.template.d.ts +5 -5
- package/dist/template/implementations/view_form.template.d.ts.map +1 -0
- package/dist/template/implementations/view_form.template.js +337 -0
- package/dist/{templates → template/implementations}/view_id_all_select.template.d.ts +3 -3
- package/dist/template/implementations/view_id_all_select.template.d.ts.map +1 -0
- package/dist/template/implementations/view_id_all_select.template.js +31 -0
- package/dist/{templates → template/implementations}/view_id_async_select.template.d.ts +3 -3
- package/dist/template/implementations/view_id_async_select.template.d.ts.map +1 -0
- package/dist/template/implementations/view_id_async_select.template.js +105 -0
- package/dist/{templates → template/implementations}/view_list.template.d.ts +5 -13
- package/dist/template/implementations/view_list.template.d.ts.map +1 -0
- package/dist/template/implementations/view_list.template.js +475 -0
- package/dist/template/implementations/view_list_columns.template.d.ts +17 -0
- package/dist/template/implementations/view_list_columns.template.d.ts.map +1 -0
- package/dist/template/implementations/view_list_columns.template.js +49 -0
- package/dist/{templates → template/implementations}/view_search_input.template.d.ts +3 -3
- package/dist/template/implementations/view_search_input.template.d.ts.map +1 -0
- package/dist/template/implementations/view_search_input.template.js +64 -0
- package/dist/template/index.d.ts +7 -0
- package/dist/template/index.d.ts.map +1 -0
- package/dist/template/index.js +8 -0
- package/dist/template/template-manager.d.ts +56 -0
- package/dist/template/template-manager.d.ts.map +1 -0
- package/dist/template/template-manager.js +125 -0
- package/dist/template/template-types.d.ts +16 -0
- package/dist/template/template-types.d.ts.map +1 -0
- package/dist/template/template-types.js +7 -0
- package/dist/template/template.d.ts +49 -0
- package/dist/template/template.d.ts.map +1 -0
- package/dist/template/template.js +60 -0
- package/dist/template/zod-converter.d.ts +51 -0
- package/dist/template/zod-converter.d.ts.map +1 -0
- package/dist/template/zod-converter.js +449 -0
- package/dist/testing/_relation-graph.d.ts +1 -1
- package/dist/testing/_relation-graph.d.ts.map +1 -1
- package/dist/testing/_relation-graph.js +89 -2
- package/dist/testing/fixture-manager.d.ts +42 -11
- package/dist/testing/fixture-manager.d.ts.map +1 -1
- package/dist/testing/fixture-manager.js +623 -2
- package/dist/types/types.d.ts +747 -143
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +546 -2
- package/dist/typings/knex.d.js +3 -2
- package/dist/utils/async-utils.d.ts +7 -0
- package/dist/utils/async-utils.d.ts.map +1 -1
- package/dist/utils/async-utils.js +57 -2
- package/dist/utils/console-util.d.ts +2 -0
- package/dist/utils/console-util.d.ts.map +1 -0
- package/dist/utils/console-util.js +6 -0
- package/dist/utils/controller.d.ts +1 -0
- package/dist/utils/controller.d.ts.map +1 -1
- package/dist/utils/controller.js +29 -2
- package/dist/utils/esm-utils.d.ts +39 -0
- package/dist/utils/esm-utils.d.ts.map +1 -0
- package/dist/utils/esm-utils.js +49 -0
- package/dist/utils/formatter.d.ts +3 -0
- package/dist/utils/formatter.d.ts.map +1 -0
- package/dist/utils/formatter.js +110 -0
- package/dist/utils/fs-utils.d.ts +1 -1
- package/dist/utils/fs-utils.d.ts.map +1 -1
- package/dist/utils/fs-utils.js +17 -2
- package/dist/utils/lodash-able.d.ts.map +1 -1
- package/dist/utils/lodash-able.js +6 -2
- package/dist/utils/model.js +22 -2
- package/dist/utils/object-utils.d.ts +44 -0
- package/dist/utils/object-utils.d.ts.map +1 -0
- package/dist/utils/object-utils.js +191 -0
- package/dist/utils/path-utils.d.ts +89 -0
- package/dist/utils/path-utils.d.ts.map +1 -0
- package/dist/utils/path-utils.js +60 -0
- package/dist/utils/process-utils.d.ts +13 -0
- package/dist/utils/process-utils.d.ts.map +1 -0
- package/dist/utils/process-utils.js +36 -0
- package/dist/utils/sql-parser.d.ts +5 -1
- package/dist/utils/sql-parser.d.ts.map +1 -1
- package/dist/utils/sql-parser.js +46 -2
- package/dist/utils/type-utils.d.ts +23 -0
- package/dist/utils/type-utils.d.ts.map +1 -0
- package/dist/utils/type-utils.js +45 -0
- package/dist/utils/utils.d.ts +10 -7
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +72 -2
- package/dist/utils/zod-error.d.ts +1 -1
- package/dist/utils/zod-error.d.ts.map +1 -1
- package/dist/utils/zod-error.js +19 -2
- package/package.json +65 -27
- package/src/ai/agents/agent.ts +87 -0
- package/src/ai/agents/index.ts +2 -0
- package/src/ai/agents/types.ts +47 -0
- package/src/ai/index.ts +1 -0
- package/src/ai/providers/rtzr/api.ts +37 -0
- package/src/ai/providers/rtzr/error.ts +34 -0
- package/src/ai/providers/rtzr/index.ts +4 -0
- package/src/ai/providers/rtzr/model.ts +201 -0
- package/src/ai/providers/rtzr/options.ts +49 -0
- package/src/ai/providers/rtzr/provider.ts +91 -0
- package/src/ai/providers/rtzr/utils.ts +127 -0
- package/src/api/base-frame.ts +4 -2
- package/src/api/caster.ts +17 -23
- package/src/api/code-converters.ts +178 -535
- package/src/api/config.ts +125 -0
- package/src/api/context.ts +7 -17
- package/src/api/decorators.ts +176 -46
- package/src/api/index.ts +2 -2
- package/src/api/sonamu.ts +190 -167
- package/src/api/validator.ts +83 -0
- package/src/bin/build-config.ts +8 -1
- package/src/bin/cli.ts +258 -124
- package/src/bin/hot-hook-register.ts +22 -0
- package/src/bin/loader-register.ts +38 -0
- package/src/database/_batch_update.ts +46 -31
- package/src/database/base-model.ts +390 -182
- package/src/database/base-model.types.ts +155 -0
- package/src/database/code-generator.ts +13 -32
- package/src/database/db.ts +40 -96
- package/src/database/puri-subset.test-d.ts +471 -0
- package/src/database/puri-subset.types.ts +195 -0
- package/src/database/puri-wrapper.ts +58 -67
- package/src/database/puri.ts +229 -148
- package/src/database/puri.types.ts +76 -30
- package/src/database/transaction-context.ts +1 -1
- package/src/database/upsert-builder.ts +262 -132
- package/src/entity/entity-manager.ts +48 -36
- package/src/entity/entity.ts +330 -248
- package/src/exceptions/error-handler.ts +3 -3
- package/src/exceptions/so-exceptions.ts +11 -11
- package/src/file-storage/driver.ts +5 -5
- package/src/file-storage/file-storage.ts +2 -2
- package/src/index.ts +18 -10
- package/src/migration/code-generation.ts +185 -172
- package/src/migration/migration-set.ts +80 -293
- package/src/migration/migrator.ts +199 -571
- package/src/migration/mysql-schema-reader.ts.txt +272 -0
- package/src/migration/postgresql-schema-reader.ts +310 -0
- package/src/migration/types.ts +6 -39
- package/src/naite/messaging-types.ts +51 -0
- package/src/naite/naite-reporter.ts +128 -0
- package/src/naite/naite.ts +415 -0
- package/src/shared/web.shared.ts.txt +20 -24
- package/src/stream/sse.ts +5 -5
- package/src/syncer/api-parser.ts +282 -0
- package/src/syncer/checksum.ts +140 -0
- package/src/syncer/code-generator.ts +198 -0
- package/src/syncer/entity-operations.ts +65 -0
- package/src/syncer/file-patterns.ts +56 -0
- package/src/syncer/index.ts +6 -0
- package/src/syncer/module-loader.ts +128 -0
- package/src/syncer/syncer.ts +389 -1453
- package/src/template/entity-converter.ts +114 -0
- package/src/template/helpers.ts +81 -0
- package/src/{templates → template/implementations}/entity.template.ts +7 -7
- package/src/{templates → template/implementations}/generated.template.ts +101 -101
- package/src/{templates → template/implementations}/generated_http.template.ts +27 -57
- package/src/template/implementations/generated_sso.template.ts +151 -0
- package/src/{templates → template/implementations}/init_types.template.ts +5 -7
- package/src/{templates → template/implementations}/model.template.ts +52 -43
- package/src/{templates → template/implementations}/model_test.template.ts +5 -5
- package/src/{templates → template/implementations}/service.template.ts +66 -82
- package/src/{templates → template/implementations}/view_enums_buttonset.template.ts +3 -3
- package/src/{templates → template/implementations}/view_enums_dropdown.template.ts +4 -20
- package/src/{templates → template/implementations}/view_enums_select.template.ts +4 -4
- package/src/{templates → template/implementations}/view_form.template.ts +40 -83
- package/src/{templates → template/implementations}/view_id_all_select.template.ts +3 -3
- package/src/{templates → template/implementations}/view_id_async_select.template.ts +10 -24
- package/src/{templates → template/implementations}/view_list.template.ts +60 -152
- package/src/{templates → template/implementations}/view_list_columns.template.ts +5 -11
- package/src/{templates → template/implementations}/view_search_input.template.ts +3 -3
- package/src/template/index.ts +6 -0
- package/src/template/template-manager.ts +166 -0
- package/src/template/template-types.ts +16 -0
- package/src/template/template.ts +105 -0
- package/src/template/zod-converter.ts +525 -0
- package/src/testing/_relation-graph.ts +18 -11
- package/src/testing/fixture-manager.ts +472 -359
- package/src/types/types.ts +553 -308
- package/src/typings/knex.d.ts +7 -9
- package/src/utils/async-utils.ts +23 -10
- package/src/utils/console-util.ts +4 -0
- package/src/utils/controller.ts +3 -0
- package/src/utils/esm-utils.ts +59 -0
- package/src/utils/formatter.ts +109 -0
- package/src/utils/fs-utils.ts +1 -1
- package/src/utils/lodash-able.ts +1 -4
- package/src/utils/object-utils.ts +217 -0
- package/src/utils/path-utils.ts +99 -0
- package/src/utils/process-utils.ts +46 -0
- package/src/utils/sql-parser.ts +23 -5
- package/src/utils/type-utils.ts +83 -0
- package/src/utils/utils.ts +66 -43
- package/src/utils/zod-error.ts +3 -4
- package/dist/api/base-frame.js.map +0 -1
- package/dist/api/caster.js.map +0 -1
- package/dist/api/code-converters.js.map +0 -1
- package/dist/api/context.js.map +0 -1
- package/dist/api/decorators.js.map +0 -1
- package/dist/api/index.js.map +0 -1
- package/dist/api/sonamu.js.map +0 -1
- package/dist/bin/build-config.js.map +0 -1
- package/dist/bin/cli-wrapper.d.ts +0 -3
- package/dist/bin/cli-wrapper.d.ts.map +0 -1
- package/dist/bin/cli-wrapper.js +0 -3
- package/dist/bin/cli-wrapper.js.map +0 -1
- package/dist/bin/cli.js.map +0 -1
- package/dist/database/_batch_update.js.map +0 -1
- package/dist/database/base-model.js.map +0 -1
- package/dist/database/code-generator.js.map +0 -1
- package/dist/database/db.js.map +0 -1
- package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts +0 -2
- package/dist/database/knex-plugins/knex-on-duplicate-update.d.ts.map +0 -1
- package/dist/database/knex-plugins/knex-on-duplicate-update.js +0 -2
- package/dist/database/knex-plugins/knex-on-duplicate-update.js.map +0 -1
- package/dist/database/puri-wrapper.js.map +0 -1
- package/dist/database/puri.js.map +0 -1
- package/dist/database/puri.types.js.map +0 -1
- package/dist/database/transaction-context.js.map +0 -1
- package/dist/database/upsert-builder.js.map +0 -1
- package/dist/entity/entity-manager.js.map +0 -1
- package/dist/entity/entity-utils.d.ts +0 -61
- package/dist/entity/entity-utils.d.ts.map +0 -1
- package/dist/entity/entity-utils.js +0 -2
- package/dist/entity/entity-utils.js.map +0 -1
- package/dist/entity/entity.js.map +0 -1
- package/dist/exceptions/error-handler.js.map +0 -1
- package/dist/exceptions/so-exceptions.js.map +0 -1
- package/dist/file-storage/driver.js.map +0 -1
- package/dist/file-storage/file-storage.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/migration/code-generation.js.map +0 -1
- package/dist/migration/migration-set.js.map +0 -1
- package/dist/migration/migrator.js.map +0 -1
- package/dist/migration/types.js.map +0 -1
- package/dist/stream/index.js.map +0 -1
- package/dist/stream/sse.js.map +0 -1
- package/dist/syncer/index.js.map +0 -1
- package/dist/syncer/syncer.js.map +0 -1
- package/dist/templates/base-template.d.ts +0 -13
- package/dist/templates/base-template.d.ts.map +0 -1
- package/dist/templates/base-template.js +0 -2
- package/dist/templates/base-template.js.map +0 -1
- package/dist/templates/entity.template.d.ts.map +0 -1
- package/dist/templates/entity.template.js +0 -2
- package/dist/templates/entity.template.js.map +0 -1
- package/dist/templates/generated.template.d.ts.map +0 -1
- package/dist/templates/generated.template.js +0 -2
- package/dist/templates/generated.template.js.map +0 -1
- package/dist/templates/generated_http.template.d.ts.map +0 -1
- package/dist/templates/generated_http.template.js +0 -2
- package/dist/templates/generated_http.template.js.map +0 -1
- package/dist/templates/generated_sso.template.d.ts.map +0 -1
- package/dist/templates/generated_sso.template.js +0 -2
- package/dist/templates/generated_sso.template.js.map +0 -1
- package/dist/templates/index.d.ts +0 -2
- package/dist/templates/index.d.ts.map +0 -1
- package/dist/templates/index.js +0 -2
- package/dist/templates/index.js.map +0 -1
- package/dist/templates/init_types.template.d.ts.map +0 -1
- package/dist/templates/init_types.template.js +0 -2
- package/dist/templates/init_types.template.js.map +0 -1
- package/dist/templates/model.template.d.ts +0 -17
- package/dist/templates/model.template.d.ts.map +0 -1
- package/dist/templates/model.template.js +0 -2
- package/dist/templates/model.template.js.map +0 -1
- package/dist/templates/model_test.template.d.ts.map +0 -1
- package/dist/templates/model_test.template.js +0 -2
- package/dist/templates/model_test.template.js.map +0 -1
- package/dist/templates/service.template.d.ts.map +0 -1
- package/dist/templates/service.template.js +0 -2
- package/dist/templates/service.template.js.map +0 -1
- package/dist/templates/view_enums_buttonset.template.d.ts.map +0 -1
- package/dist/templates/view_enums_buttonset.template.js +0 -2
- package/dist/templates/view_enums_buttonset.template.js.map +0 -1
- package/dist/templates/view_enums_dropdown.template.d.ts.map +0 -1
- package/dist/templates/view_enums_dropdown.template.js +0 -2
- package/dist/templates/view_enums_dropdown.template.js.map +0 -1
- package/dist/templates/view_enums_select.template.d.ts.map +0 -1
- package/dist/templates/view_enums_select.template.js +0 -2
- package/dist/templates/view_enums_select.template.js.map +0 -1
- package/dist/templates/view_form.template.d.ts.map +0 -1
- package/dist/templates/view_form.template.js +0 -2
- package/dist/templates/view_form.template.js.map +0 -1
- package/dist/templates/view_id_all_select.template.d.ts.map +0 -1
- package/dist/templates/view_id_all_select.template.js +0 -2
- package/dist/templates/view_id_all_select.template.js.map +0 -1
- package/dist/templates/view_id_async_select.template.d.ts.map +0 -1
- package/dist/templates/view_id_async_select.template.js +0 -2
- package/dist/templates/view_id_async_select.template.js.map +0 -1
- package/dist/templates/view_list.template.d.ts.map +0 -1
- package/dist/templates/view_list.template.js +0 -2
- package/dist/templates/view_list.template.js.map +0 -1
- package/dist/templates/view_list_columns.template.d.ts +0 -17
- package/dist/templates/view_list_columns.template.d.ts.map +0 -1
- package/dist/templates/view_list_columns.template.js +0 -2
- package/dist/templates/view_list_columns.template.js.map +0 -1
- package/dist/templates/view_search_input.template.d.ts.map +0 -1
- package/dist/templates/view_search_input.template.js +0 -2
- package/dist/templates/view_search_input.template.js.map +0 -1
- package/dist/testing/_relation-graph.js.map +0 -1
- package/dist/testing/fixture-manager.js.map +0 -1
- package/dist/types/types.js.map +0 -1
- package/dist/typings/knex.d.js.map +0 -1
- package/dist/utils/async-utils.js.map +0 -1
- package/dist/utils/controller.js.map +0 -1
- package/dist/utils/fs-utils.js.map +0 -1
- package/dist/utils/lodash-able.js.map +0 -1
- package/dist/utils/model.js.map +0 -1
- package/dist/utils/sql-parser.js.map +0 -1
- package/dist/utils/utils.js.map +0 -1
- package/dist/utils/zod-error.js.map +0 -1
- package/src/bin/cli-wrapper.ts +0 -75
- package/src/database/knex-plugins/knex-on-duplicate-update.ts +0 -45
- package/src/entity/entity-utils.ts +0 -291
- package/src/templates/base-template.ts +0 -19
- package/src/templates/generated_sso.template.ts +0 -138
- package/src/templates/index.ts +0 -1
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// 일단 참고자료로 남겨두었으나, PG 전환 완료 이후 삭제 예정
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import assert from "assert";
|
|
6
|
+
import type { Knex } from "knex";
|
|
7
|
+
import { group } from "radashi";
|
|
8
|
+
import {
|
|
9
|
+
isKnexError,
|
|
10
|
+
type MigrationColumn,
|
|
11
|
+
type MigrationForeign,
|
|
12
|
+
type MigrationIndex,
|
|
13
|
+
type MigrationSet,
|
|
14
|
+
type RelationOn,
|
|
15
|
+
} from "../types/types";
|
|
16
|
+
|
|
17
|
+
type MyColumn = {
|
|
18
|
+
Field: string;
|
|
19
|
+
Type: string;
|
|
20
|
+
Null: string;
|
|
21
|
+
Key: string;
|
|
22
|
+
Default: string | null;
|
|
23
|
+
Extra: string;
|
|
24
|
+
};
|
|
25
|
+
type MyIndex = {
|
|
26
|
+
Table: string;
|
|
27
|
+
Non_unique: number;
|
|
28
|
+
Key_name: string;
|
|
29
|
+
Seq_in_index: number;
|
|
30
|
+
Column_name: string;
|
|
31
|
+
Collation: string | null;
|
|
32
|
+
Cardinality: number | null;
|
|
33
|
+
Sub_part: number | null;
|
|
34
|
+
Packed: string | null;
|
|
35
|
+
Null: string;
|
|
36
|
+
Index_type: string;
|
|
37
|
+
Comment: string;
|
|
38
|
+
Index_comment: string;
|
|
39
|
+
Visible: string;
|
|
40
|
+
Expression: string | null;
|
|
41
|
+
};
|
|
42
|
+
type MyForeign = {
|
|
43
|
+
keyName: string;
|
|
44
|
+
from: string;
|
|
45
|
+
referencesTable: string;
|
|
46
|
+
referencesField: string;
|
|
47
|
+
onDelete: string;
|
|
48
|
+
onUpdate: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
class MySQLSchemaReaderClass {
|
|
52
|
+
/**
|
|
53
|
+
* DB에서 테이블 정보를 읽어서 MigrationSet을 만들어옵니다.
|
|
54
|
+
* @param compareDB Knex 인스턴스
|
|
55
|
+
* @param table 테이블 이름
|
|
56
|
+
* @returns MigrationSet 객체
|
|
57
|
+
*/
|
|
58
|
+
async getMigrationSetFromDB(compareDB: Knex, table: string): Promise<MigrationSet | null> {
|
|
59
|
+
let dbColumns: MyColumn[], dbIndexes: MyIndex[], dbForeigns: MyForeign[];
|
|
60
|
+
try {
|
|
61
|
+
[dbColumns, dbIndexes, dbForeigns] = await this.readTable(compareDB, table);
|
|
62
|
+
} catch (e: unknown) {
|
|
63
|
+
if (isKnexError(e) && e.code === "ER_NO_SUCH_TABLE") {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
console.error(e);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const columns: MigrationColumn[] = dbColumns.map((dbColumn) => {
|
|
71
|
+
const dbColType = this.resolveDBColType(dbColumn.Type, dbColumn.Field);
|
|
72
|
+
return {
|
|
73
|
+
name: dbColumn.Field,
|
|
74
|
+
nullable: dbColumn.Null !== "NO",
|
|
75
|
+
...dbColType,
|
|
76
|
+
...(() => {
|
|
77
|
+
if (dbColumn.Default !== null) {
|
|
78
|
+
return {
|
|
79
|
+
defaultTo: dbColumn.Default,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {};
|
|
83
|
+
})(),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const dbIndexesGroup = group(
|
|
88
|
+
dbIndexes.filter(
|
|
89
|
+
(dbIndex) =>
|
|
90
|
+
dbIndex.Key_name !== "PRIMARY" &&
|
|
91
|
+
!dbForeigns.find((dbForeign) => dbForeign.keyName === dbIndex.Key_name),
|
|
92
|
+
),
|
|
93
|
+
(dbIndex) => dbIndex.Key_name,
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const parseIndexType = (index: MyIndex) => {
|
|
97
|
+
if (index.Index_type === "FULLTEXT") {
|
|
98
|
+
return "fulltext";
|
|
99
|
+
}
|
|
100
|
+
return index.Non_unique === 1 ? "index" : "unique";
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// indexes 처리
|
|
104
|
+
const indexes: MigrationIndex[] = Object.keys(dbIndexesGroup).map((keyName) => {
|
|
105
|
+
const currentIndexes = dbIndexesGroup[keyName];
|
|
106
|
+
assert(currentIndexes);
|
|
107
|
+
return {
|
|
108
|
+
type: parseIndexType(currentIndexes[0]),
|
|
109
|
+
columns: currentIndexes.map((currentIndex) => currentIndex.Column_name),
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
// console.log(table);
|
|
113
|
+
// console.table(dbIndexes);
|
|
114
|
+
// console.table(dbForeigns);
|
|
115
|
+
|
|
116
|
+
// foreigns 처리
|
|
117
|
+
const foreigns: MigrationForeign[] = dbForeigns.map((dbForeign) => {
|
|
118
|
+
return {
|
|
119
|
+
columns: [dbForeign.from],
|
|
120
|
+
to: `${dbForeign.referencesTable}.${dbForeign.referencesField}`,
|
|
121
|
+
onUpdate: dbForeign.onUpdate as RelationOn,
|
|
122
|
+
onDelete: dbForeign.onDelete as RelationOn,
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
table,
|
|
128
|
+
columns,
|
|
129
|
+
indexes,
|
|
130
|
+
foreigns,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/*
|
|
135
|
+
* 기존 테이블 읽어서 cols, indexes 반환
|
|
136
|
+
*/
|
|
137
|
+
async readTable(
|
|
138
|
+
compareDB: Knex,
|
|
139
|
+
tableName: string,
|
|
140
|
+
): Promise<[MyColumn[], MyIndex[], MyForeign[]]> {
|
|
141
|
+
const [_cols] = (await compareDB.raw(`SHOW FIELDS FROM ${tableName}`)) as [MyColumn[]];
|
|
142
|
+
const cols = _cols.map((col) => ({
|
|
143
|
+
...col,
|
|
144
|
+
// Default 값은 숫자나 MySQL Expression이 아닌 경우 ""로 감싸줌
|
|
145
|
+
...(col.Default !== null && {
|
|
146
|
+
Default:
|
|
147
|
+
col.Default.replace(/[0-9]+/g, "").length > 0 && col.Extra !== "DEFAULT_GENERATED"
|
|
148
|
+
? `"${col.Default}"`
|
|
149
|
+
: col.Default,
|
|
150
|
+
}),
|
|
151
|
+
}));
|
|
152
|
+
|
|
153
|
+
const [indexes] = await compareDB.raw(`SHOW INDEX FROM ${tableName}`);
|
|
154
|
+
const [[row]] = await compareDB.raw(`SHOW CREATE TABLE ${tableName}`);
|
|
155
|
+
const ddl = row["Create Table"];
|
|
156
|
+
const matched = ddl.match(/CONSTRAINT .+/g);
|
|
157
|
+
const foreignKeys = (matched ?? []).map((line: string) => {
|
|
158
|
+
// 해당 라인을 정규식으로 파싱
|
|
159
|
+
const matched = line.match(
|
|
160
|
+
/CONSTRAINT `(.+)` FOREIGN KEY \(`(.+)`\) REFERENCES `(.+)` \(`(.+)`\)( ON [A-Z ]+)*/,
|
|
161
|
+
);
|
|
162
|
+
if (!matched) {
|
|
163
|
+
throw new Error(`인식할 수 없는 FOREIGN KEY CONSTRAINT ${line}`);
|
|
164
|
+
}
|
|
165
|
+
const [, keyName, from, referencesTable, referencesField, onClause] = matched;
|
|
166
|
+
// console.debug({ tableName, line, onClause });
|
|
167
|
+
|
|
168
|
+
const [onUpdateFull, _onUpdate] = (onClause ?? "").match(/ON UPDATE ([A-Z ]+)$/) ?? [];
|
|
169
|
+
const onUpdate = _onUpdate ?? "NO ACTION";
|
|
170
|
+
|
|
171
|
+
const onDelete =
|
|
172
|
+
(onClause ?? "")
|
|
173
|
+
.replace(onUpdateFull ?? "", "")
|
|
174
|
+
.match(/ON DELETE ([A-Z ]+)/)?.[1]
|
|
175
|
+
?.trim() ?? "NO ACTION";
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
keyName,
|
|
179
|
+
from,
|
|
180
|
+
referencesTable,
|
|
181
|
+
referencesField,
|
|
182
|
+
onDelete,
|
|
183
|
+
onUpdate,
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
return [cols, indexes, foreignKeys];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* DB의 컬럼 타입을 분석하여 MigrationColumn 객체로 변환합니다.
|
|
191
|
+
* @param colType DB 컬럼 타입
|
|
192
|
+
* @param colField DB 컬럼 이름
|
|
193
|
+
* @returns MigrationColumn
|
|
194
|
+
*/
|
|
195
|
+
resolveDBColType(
|
|
196
|
+
colType: string,
|
|
197
|
+
colField: string,
|
|
198
|
+
): Pick<MigrationColumn, "type" | "unsigned" | "length" | "precision" | "scale"> {
|
|
199
|
+
let [rawType, unsigned] = colType.split(" ");
|
|
200
|
+
const matched = rawType.match(/\(([0-9]+)\)/);
|
|
201
|
+
let length: number | undefined;
|
|
202
|
+
if (matched?.[1]) {
|
|
203
|
+
rawType = rawType.replace(/\(([0-9]+)\)/, "");
|
|
204
|
+
length = parseInt(matched[1]);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (rawType === "char" && colField === "uuid") {
|
|
208
|
+
return {
|
|
209
|
+
type: "uuid",
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
switch (rawType) {
|
|
214
|
+
case "int":
|
|
215
|
+
return {
|
|
216
|
+
type: "integer",
|
|
217
|
+
unsigned: unsigned === "unsigned",
|
|
218
|
+
};
|
|
219
|
+
case "varchar":
|
|
220
|
+
// case "char":
|
|
221
|
+
return {
|
|
222
|
+
type: "string",
|
|
223
|
+
...(length !== undefined && {
|
|
224
|
+
length,
|
|
225
|
+
}),
|
|
226
|
+
};
|
|
227
|
+
case "text":
|
|
228
|
+
case "mediumtext":
|
|
229
|
+
case "longtext":
|
|
230
|
+
case "timestamp":
|
|
231
|
+
case "json":
|
|
232
|
+
case "date":
|
|
233
|
+
case "time":
|
|
234
|
+
return {
|
|
235
|
+
type: rawType,
|
|
236
|
+
};
|
|
237
|
+
case "datetime":
|
|
238
|
+
return {
|
|
239
|
+
type: "datetime",
|
|
240
|
+
};
|
|
241
|
+
case "tinyint":
|
|
242
|
+
return {
|
|
243
|
+
type: "boolean",
|
|
244
|
+
};
|
|
245
|
+
default:
|
|
246
|
+
// decimal 처리
|
|
247
|
+
if (rawType.startsWith("decimal")) {
|
|
248
|
+
const [, precision, scale] = rawType.match(/decimal\(([0-9]+),([0-9]+)\)/) ?? [];
|
|
249
|
+
return {
|
|
250
|
+
type: "decimal",
|
|
251
|
+
precision: parseInt(precision),
|
|
252
|
+
scale: parseInt(scale),
|
|
253
|
+
...(unsigned === "unsigned" && {
|
|
254
|
+
unsigned: true,
|
|
255
|
+
}),
|
|
256
|
+
};
|
|
257
|
+
} else if (rawType.startsWith("float")) {
|
|
258
|
+
const [, precision, scale] = rawType.match(/float\(([0-9]+),([0-9]+)\)/) ?? [];
|
|
259
|
+
return {
|
|
260
|
+
type: "float",
|
|
261
|
+
precision: parseInt(precision),
|
|
262
|
+
scale: parseInt(scale),
|
|
263
|
+
...(unsigned === "unsigned" && {
|
|
264
|
+
unsigned: true,
|
|
265
|
+
}),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
throw new Error(`resolve 불가능한 DB컬럼 타입 ${colType} ${rawType}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
export const MySQLSchemaReader = new MySQLSchemaReaderClass();
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import type { Knex } from "knex";
|
|
3
|
+
import { group } from "radashi";
|
|
4
|
+
import type {
|
|
5
|
+
MigrationColumn,
|
|
6
|
+
MigrationForeign,
|
|
7
|
+
MigrationIndex,
|
|
8
|
+
MigrationSet,
|
|
9
|
+
RelationOn,
|
|
10
|
+
} from "../types/types";
|
|
11
|
+
|
|
12
|
+
export type PgColumn = {
|
|
13
|
+
column_name: string;
|
|
14
|
+
data_type: string;
|
|
15
|
+
udt_name: string;
|
|
16
|
+
character_maximum_length: number | null;
|
|
17
|
+
numeric_precision: number | null;
|
|
18
|
+
numeric_scale: number | null;
|
|
19
|
+
is_nullable: string;
|
|
20
|
+
column_default: string | null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type PgIndex = {
|
|
24
|
+
index_name: string;
|
|
25
|
+
column_name: string;
|
|
26
|
+
is_unique: boolean;
|
|
27
|
+
is_primary: boolean;
|
|
28
|
+
index_type: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type PgForeign = {
|
|
32
|
+
constraint_name: string;
|
|
33
|
+
column_name: string;
|
|
34
|
+
foreign_table_name: string;
|
|
35
|
+
foreign_column_name: string;
|
|
36
|
+
update_rule: string;
|
|
37
|
+
delete_rule: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
class PostgreSQLSchemaReaderClass {
|
|
41
|
+
/**
|
|
42
|
+
* DB에서 테이블 정보를 읽어서 MigrationSet을 만들어옵니다.
|
|
43
|
+
* @param compareDB Knex 인스턴스
|
|
44
|
+
* @param table 테이블 이름
|
|
45
|
+
* @returns MigrationSet 객체
|
|
46
|
+
*/
|
|
47
|
+
async getMigrationSetFromDB(compareDB: Knex, table: string): Promise<MigrationSet | null> {
|
|
48
|
+
let dbColumns: PgColumn[], dbIndexes: PgIndex[], dbForeigns: PgForeign[];
|
|
49
|
+
try {
|
|
50
|
+
[dbColumns, dbIndexes, dbForeigns] = await this.readTable(compareDB, table);
|
|
51
|
+
} catch (e: unknown) {
|
|
52
|
+
if (e instanceof Error && e.message.includes("Table not found")) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
console.error(e);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const columns: MigrationColumn[] = dbColumns.map((dbColumn) => {
|
|
60
|
+
const dbColType = this.resolveDBColType(dbColumn);
|
|
61
|
+
return {
|
|
62
|
+
name: dbColumn.column_name,
|
|
63
|
+
nullable: dbColumn.is_nullable === "YES",
|
|
64
|
+
...dbColType,
|
|
65
|
+
...(() => {
|
|
66
|
+
if (dbColumn.column_default !== null) {
|
|
67
|
+
// PostgreSQL default 값 정리 (nextval, CURRENT_TIMESTAMP 등)
|
|
68
|
+
let defaultValue = dbColumn.column_default;
|
|
69
|
+
|
|
70
|
+
// nextval 제거 (SERIAL 타입)
|
|
71
|
+
if (defaultValue.startsWith("nextval(")) {
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 타입 캐스팅 제거 (예: '1'::integer → 1)
|
|
76
|
+
defaultValue = defaultValue.replace(/::[\w\s]+$/g, "");
|
|
77
|
+
|
|
78
|
+
// 따옴표 제거가 필요한 경우
|
|
79
|
+
if (defaultValue.startsWith("'") && defaultValue.endsWith("'")) {
|
|
80
|
+
defaultValue = defaultValue.slice(1, -1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
defaultTo: defaultValue,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {};
|
|
88
|
+
})(),
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// PRIMARY KEY와 foreign key용 인덱스 제외
|
|
93
|
+
const dbIndexesGroup = group(
|
|
94
|
+
dbIndexes.filter(
|
|
95
|
+
(dbIndex) =>
|
|
96
|
+
!dbIndex.is_primary &&
|
|
97
|
+
!dbForeigns.find((dbForeign) => dbIndex.index_name.includes(dbForeign.constraint_name)),
|
|
98
|
+
),
|
|
99
|
+
(dbIndex) => dbIndex.index_name,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// indexes 처리
|
|
103
|
+
const indexes: MigrationIndex[] = Object.keys(dbIndexesGroup).map((indexName) => {
|
|
104
|
+
const currentIndexes = dbIndexesGroup[indexName];
|
|
105
|
+
assert(currentIndexes);
|
|
106
|
+
|
|
107
|
+
const firstIndex = currentIndexes[0];
|
|
108
|
+
const type = firstIndex.is_unique ? "unique" : "index";
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
type,
|
|
112
|
+
columns: currentIndexes.map((idx) => idx.column_name),
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// foreigns 처리
|
|
117
|
+
const foreigns: MigrationForeign[] = dbForeigns.map((dbForeign) => {
|
|
118
|
+
return {
|
|
119
|
+
columns: [dbForeign.column_name],
|
|
120
|
+
to: `${dbForeign.foreign_table_name}.${dbForeign.foreign_column_name}`,
|
|
121
|
+
onUpdate: this.mapConstraintAction(dbForeign.update_rule),
|
|
122
|
+
onDelete: this.mapConstraintAction(dbForeign.delete_rule),
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
table,
|
|
128
|
+
columns,
|
|
129
|
+
indexes,
|
|
130
|
+
foreigns,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* PostgreSQL의 constraint action을 Knex 형식으로 변환
|
|
136
|
+
*/
|
|
137
|
+
private mapConstraintAction(action: string): RelationOn {
|
|
138
|
+
const actionMap: Record<string, RelationOn> = {
|
|
139
|
+
"NO ACTION": "NO ACTION",
|
|
140
|
+
RESTRICT: "RESTRICT",
|
|
141
|
+
CASCADE: "CASCADE",
|
|
142
|
+
"SET NULL": "SET NULL",
|
|
143
|
+
"SET DEFAULT": "SET DEFAULT",
|
|
144
|
+
};
|
|
145
|
+
return actionMap[action] ?? "NO ACTION";
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 기존 테이블 읽어서 cols, indexes, foreigns 반환
|
|
150
|
+
*/
|
|
151
|
+
async readTable(
|
|
152
|
+
compareDB: Knex,
|
|
153
|
+
tableName: string,
|
|
154
|
+
): Promise<[PgColumn[], PgIndex[], PgForeign[]]> {
|
|
155
|
+
// Columns 조회
|
|
156
|
+
const columns = await compareDB
|
|
157
|
+
.select(
|
|
158
|
+
"column_name",
|
|
159
|
+
"data_type",
|
|
160
|
+
"udt_name",
|
|
161
|
+
"character_maximum_length",
|
|
162
|
+
"numeric_precision",
|
|
163
|
+
"numeric_scale",
|
|
164
|
+
"is_nullable",
|
|
165
|
+
"column_default",
|
|
166
|
+
)
|
|
167
|
+
.from("information_schema.columns")
|
|
168
|
+
.where({ table_name: tableName })
|
|
169
|
+
.orderBy("ordinal_position");
|
|
170
|
+
if (columns.length === 0) {
|
|
171
|
+
throw new Error(`Table not found: ${tableName}`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Indexes 조회
|
|
175
|
+
const indexesQuery = `
|
|
176
|
+
SELECT
|
|
177
|
+
i.relname as index_name,
|
|
178
|
+
a.attname as column_name,
|
|
179
|
+
ix.indisunique as is_unique,
|
|
180
|
+
ix.indisprimary as is_primary,
|
|
181
|
+
am.amname as index_type
|
|
182
|
+
FROM pg_class t
|
|
183
|
+
JOIN pg_index ix ON t.oid = ix.indrelid
|
|
184
|
+
JOIN pg_class i ON i.oid = ix.indexrelid
|
|
185
|
+
JOIN pg_attribute a ON a.attrelid = t.oid
|
|
186
|
+
JOIN pg_am am ON i.relam = am.oid
|
|
187
|
+
WHERE t.relname = ?
|
|
188
|
+
AND a.attnum = ANY(ix.indkey)
|
|
189
|
+
ORDER BY i.relname, array_position(ix.indkey, a.attnum)
|
|
190
|
+
`;
|
|
191
|
+
const indexes = (await compareDB.raw(indexesQuery, [tableName])).rows;
|
|
192
|
+
|
|
193
|
+
// Foreign Keys 조회
|
|
194
|
+
const foreignsQuery = `
|
|
195
|
+
SELECT
|
|
196
|
+
tc.constraint_name,
|
|
197
|
+
kcu.column_name,
|
|
198
|
+
ccu.table_name AS foreign_table_name,
|
|
199
|
+
ccu.column_name AS foreign_column_name,
|
|
200
|
+
rc.update_rule,
|
|
201
|
+
rc.delete_rule
|
|
202
|
+
FROM information_schema.table_constraints AS tc
|
|
203
|
+
JOIN information_schema.key_column_usage AS kcu
|
|
204
|
+
ON tc.constraint_name = kcu.constraint_name
|
|
205
|
+
AND tc.table_schema = kcu.table_schema
|
|
206
|
+
JOIN information_schema.constraint_column_usage AS ccu
|
|
207
|
+
ON ccu.constraint_name = tc.constraint_name
|
|
208
|
+
AND ccu.table_schema = tc.table_schema
|
|
209
|
+
JOIN information_schema.referential_constraints AS rc
|
|
210
|
+
ON rc.constraint_name = tc.constraint_name
|
|
211
|
+
AND rc.constraint_schema = tc.table_schema
|
|
212
|
+
WHERE tc.constraint_type = 'FOREIGN KEY'
|
|
213
|
+
AND tc.table_name = ?
|
|
214
|
+
`;
|
|
215
|
+
const foreigns = (await compareDB.raw(foreignsQuery, [tableName])).rows;
|
|
216
|
+
|
|
217
|
+
return [columns, indexes, foreigns];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* PostgreSQL 컬럼 타입을 분석하여 MigrationColumn 객체로 변환합니다.
|
|
222
|
+
*/
|
|
223
|
+
resolveDBColType(
|
|
224
|
+
dbColumn: PgColumn,
|
|
225
|
+
): Pick<MigrationColumn, "type" | "length" | "precision" | "scale" | "numberType"> {
|
|
226
|
+
const {
|
|
227
|
+
udt_name: _udt_name,
|
|
228
|
+
character_maximum_length,
|
|
229
|
+
numeric_precision,
|
|
230
|
+
numeric_scale,
|
|
231
|
+
} = dbColumn;
|
|
232
|
+
|
|
233
|
+
const { udt_name, singleOrArray } = (() => {
|
|
234
|
+
if (_udt_name.startsWith("_")) {
|
|
235
|
+
return {
|
|
236
|
+
udt_name: _udt_name.substring(1),
|
|
237
|
+
singleOrArray: "[]" as const,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
udt_name: _udt_name,
|
|
242
|
+
singleOrArray: "" as const,
|
|
243
|
+
};
|
|
244
|
+
})();
|
|
245
|
+
|
|
246
|
+
// UUID
|
|
247
|
+
if (udt_name === "uuid") {
|
|
248
|
+
return { type: `uuid${singleOrArray}` };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Integer types
|
|
252
|
+
if (udt_name === "int4") {
|
|
253
|
+
return { type: `integer${singleOrArray}` };
|
|
254
|
+
}
|
|
255
|
+
if (udt_name === "int8") {
|
|
256
|
+
return { type: `bigInteger${singleOrArray}` };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// String types
|
|
260
|
+
if (udt_name === "varchar") {
|
|
261
|
+
return {
|
|
262
|
+
type: `string${singleOrArray}`,
|
|
263
|
+
...(character_maximum_length && {
|
|
264
|
+
length: character_maximum_length,
|
|
265
|
+
}),
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
if (udt_name === "text") {
|
|
269
|
+
return { type: `string${singleOrArray}` }; // StringProp without length
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// NumberOrNumeric types
|
|
273
|
+
if (udt_name === "numeric") {
|
|
274
|
+
return {
|
|
275
|
+
type: `numberOrNumeric${singleOrArray}`,
|
|
276
|
+
numberType: "numeric",
|
|
277
|
+
...(numeric_precision !== null &&
|
|
278
|
+
numeric_scale !== null && {
|
|
279
|
+
precision: numeric_precision,
|
|
280
|
+
scale: numeric_scale,
|
|
281
|
+
}),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
if (udt_name === "float4") {
|
|
285
|
+
return { type: `numberOrNumeric${singleOrArray}`, numberType: "real" };
|
|
286
|
+
}
|
|
287
|
+
if (udt_name === "float8") {
|
|
288
|
+
return { type: `numberOrNumeric${singleOrArray}`, numberType: "double precision" };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Boolean
|
|
292
|
+
if (udt_name === "bool") {
|
|
293
|
+
return { type: `boolean${singleOrArray}` };
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Timestampz types
|
|
297
|
+
if (udt_name === "timestamptz") {
|
|
298
|
+
return { type: `date${singleOrArray}` }; // DateProp → timestamptz
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// JSON
|
|
302
|
+
if (udt_name === "json" || udt_name === "jsonb") {
|
|
303
|
+
return { type: "json" };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
throw new Error(`resolve 불가능한 PostgreSQL 컬럼 타입: ${udt_name}`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export const PostgreSQLSchemaReader = new PostgreSQLSchemaReaderClass();
|
package/src/migration/types.ts
CHANGED
|
@@ -1,54 +1,21 @@
|
|
|
1
|
-
import { SonamuDBConfig } from "../database/db";
|
|
2
|
-
import { GenMigrationCode } from "../types/types";
|
|
1
|
+
import type { SonamuDBConfig } from "../database/db";
|
|
2
|
+
import type { GenMigrationCode } from "../types/types";
|
|
3
3
|
|
|
4
4
|
export type MigrationCode = {
|
|
5
5
|
name: string;
|
|
6
6
|
path: string;
|
|
7
7
|
};
|
|
8
|
-
export type ConnString =
|
|
9
|
-
`${"mysql2"}://${string}@${string}:${number}/${string}`; // mysql2://account@host:port/database
|
|
8
|
+
export type ConnString = `${"pg"}://${string}@${string}:${number}/${string}`; // pg://account@host:port/database
|
|
10
9
|
export type MigrationStatus = {
|
|
11
10
|
codes: MigrationCode[];
|
|
12
11
|
conns: {
|
|
13
12
|
name: string;
|
|
14
13
|
connKey: keyof SonamuDBConfig;
|
|
15
14
|
connString: ConnString;
|
|
16
|
-
currentVersion: string;
|
|
17
|
-
status:
|
|
15
|
+
currentVersion: string | "error";
|
|
16
|
+
status: number | "error";
|
|
18
17
|
pending: string[];
|
|
19
18
|
}[];
|
|
20
19
|
preparedCodes: GenMigrationCode[];
|
|
21
|
-
|
|
22
|
-
export type DBColumn = {
|
|
23
|
-
Field: string;
|
|
24
|
-
Type: string;
|
|
25
|
-
Null: string;
|
|
26
|
-
Key: string;
|
|
27
|
-
Default: string | null;
|
|
28
|
-
Extra: string;
|
|
29
|
-
};
|
|
30
|
-
export type DBIndex = {
|
|
31
|
-
Table: string;
|
|
32
|
-
Non_unique: number;
|
|
33
|
-
Key_name: string;
|
|
34
|
-
Seq_in_index: number;
|
|
35
|
-
Column_name: string;
|
|
36
|
-
Collation: string | null;
|
|
37
|
-
Cardinality: number | null;
|
|
38
|
-
Sub_part: number | null;
|
|
39
|
-
Packed: string | null;
|
|
40
|
-
Null: string;
|
|
41
|
-
Index_type: string;
|
|
42
|
-
Comment: string;
|
|
43
|
-
Index_comment: string;
|
|
44
|
-
Visible: string;
|
|
45
|
-
Expression: string | null;
|
|
46
|
-
};
|
|
47
|
-
export type DBForeign = {
|
|
48
|
-
keyName: string;
|
|
49
|
-
from: string;
|
|
50
|
-
referencesTable: string;
|
|
51
|
-
referencesField: string;
|
|
52
|
-
onDelete: string;
|
|
53
|
-
onUpdate: string;
|
|
20
|
+
error?: string;
|
|
54
21
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: Naite는 expect와 호응하도록 any를 허용함
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sonamu extension과 공유하는 Naite 메시징 관련 타입 정의들입니다.
|
|
5
|
+
* 이 파일은 cartanova-ai/sonamu와 cartanova-ai/vscode-sonamu에서 공통으로 사용됩니다.
|
|
6
|
+
*/
|
|
7
|
+
export namespace NaiteMessagingTypes {
|
|
8
|
+
export type NaiteRunStartMessage = {
|
|
9
|
+
type: "run/start";
|
|
10
|
+
startedAt: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type NaiteTestResultMessage = {
|
|
14
|
+
type: "test/result";
|
|
15
|
+
receivedAt: string;
|
|
16
|
+
} & TestResult;
|
|
17
|
+
|
|
18
|
+
export type NaiteRunEndMessage = {
|
|
19
|
+
type: "run/end";
|
|
20
|
+
endedAt: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type NaiteMessage = NaiteRunStartMessage | NaiteTestResultMessage | NaiteRunEndMessage;
|
|
24
|
+
|
|
25
|
+
export type NaiteTrace = {
|
|
26
|
+
key: string;
|
|
27
|
+
value: any;
|
|
28
|
+
filePath: string;
|
|
29
|
+
lineNumber: number;
|
|
30
|
+
at: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type TestError = {
|
|
34
|
+
message: string;
|
|
35
|
+
stack?: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type TestResult = {
|
|
39
|
+
suiteName: string;
|
|
40
|
+
suiteFilePath?: string;
|
|
41
|
+
testName: string;
|
|
42
|
+
testFilePath: string;
|
|
43
|
+
testLine: number;
|
|
44
|
+
status: string;
|
|
45
|
+
duration: number;
|
|
46
|
+
error?: TestError;
|
|
47
|
+
traces: NaiteTrace[];
|
|
48
|
+
receivedAt: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|