@hypequery/clickhouse 1.6.2 → 2.0.1

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.
Files changed (142) hide show
  1. package/README-CLI.md +43 -88
  2. package/README.md +84 -253
  3. package/dist/cli/bin.js +16 -8
  4. package/dist/core/adapters/clickhouse-adapter.d.ts.map +1 -1
  5. package/dist/core/adapters/clickhouse-adapter.js +3 -2
  6. package/dist/core/cache/cache-manager.d.ts.map +1 -1
  7. package/dist/core/cache/cache-manager.js +5 -3
  8. package/dist/core/connection.d.ts +6 -6
  9. package/dist/core/connection.js +9 -9
  10. package/dist/core/cross-filter.js +1 -1
  11. package/dist/core/dialects/clickhouse-dialect.d.ts +2 -2
  12. package/dist/core/dialects/clickhouse-dialect.d.ts.map +1 -1
  13. package/dist/core/dialects/clickhouse-dialect.js +39 -22
  14. package/dist/core/dialects/sql-dialect.d.ts +2 -2
  15. package/dist/core/dialects/sql-dialect.d.ts.map +1 -1
  16. package/dist/core/env/auto-client.d.ts.map +1 -1
  17. package/dist/core/env/auto-client.js +1 -1
  18. package/dist/core/features/aggregations.d.ts +27 -84
  19. package/dist/core/features/aggregations.d.ts.map +1 -1
  20. package/dist/core/features/aggregations.js +59 -7
  21. package/dist/core/features/analytics.d.ts +5 -870
  22. package/dist/core/features/analytics.d.ts.map +1 -1
  23. package/dist/core/features/analytics.js +15 -13
  24. package/dist/core/features/cross-filtering.d.ts +1 -1
  25. package/dist/core/features/cross-filtering.d.ts.map +1 -1
  26. package/dist/core/features/cross-filtering.js +28 -73
  27. package/dist/core/features/executor.d.ts +1 -1
  28. package/dist/core/features/executor.d.ts.map +1 -1
  29. package/dist/core/features/executor.js +9 -11
  30. package/dist/core/features/filtering.d.ts +5 -91
  31. package/dist/core/features/filtering.d.ts.map +1 -1
  32. package/dist/core/features/filtering.js +63 -77
  33. package/dist/core/features/joins.d.ts +2 -19
  34. package/dist/core/features/joins.d.ts.map +1 -1
  35. package/dist/core/features/joins.js +16 -5
  36. package/dist/core/features/query-modifiers.d.ts +10 -109
  37. package/dist/core/features/query-modifiers.d.ts.map +1 -1
  38. package/dist/core/features/query-modifiers.js +64 -18
  39. package/dist/core/formatters/sql-formatter.d.ts +16 -5
  40. package/dist/core/formatters/sql-formatter.d.ts.map +1 -1
  41. package/dist/core/formatters/sql-formatter.js +197 -93
  42. package/dist/core/join-relationships.d.ts +22 -5
  43. package/dist/core/join-relationships.d.ts.map +1 -1
  44. package/dist/core/join-relationships.js +1 -1
  45. package/dist/core/query-builder.d.ts +64 -12
  46. package/dist/core/query-builder.d.ts.map +1 -1
  47. package/dist/core/query-builder.js +213 -153
  48. package/dist/core/query-node.d.ts +7 -0
  49. package/dist/core/query-node.d.ts.map +1 -0
  50. package/dist/core/query-node.js +80 -0
  51. package/dist/core/tests/integration/setup.d.ts +3 -10
  52. package/dist/core/tests/integration/setup.d.ts.map +1 -1
  53. package/dist/core/tests/integration/setup.js +30 -249
  54. package/dist/core/types/select-types.d.ts +3 -0
  55. package/dist/core/types/select-types.d.ts.map +1 -1
  56. package/dist/core/utils/connection-endpoint.d.ts +3 -0
  57. package/dist/core/utils/connection-endpoint.d.ts.map +1 -0
  58. package/dist/core/utils/connection-endpoint.js +9 -0
  59. package/dist/core/utils/filter-application.d.ts +15 -0
  60. package/dist/core/utils/filter-application.d.ts.map +1 -0
  61. package/dist/core/utils/filter-application.js +32 -0
  62. package/dist/core/utils/query-config-compat.d.ts +48 -0
  63. package/dist/core/utils/query-config-compat.d.ts.map +1 -0
  64. package/dist/core/utils/query-config-compat.js +137 -0
  65. package/dist/core/utils/relation-application.d.ts +9 -0
  66. package/dist/core/utils/relation-application.d.ts.map +1 -0
  67. package/dist/core/utils/relation-application.js +19 -0
  68. package/dist/core/utils/relation-validation.d.ts +6 -0
  69. package/dist/core/utils/relation-validation.d.ts.map +1 -0
  70. package/dist/core/utils/relation-validation.js +29 -0
  71. package/dist/core/utils/sql-expressions.d.ts +14 -0
  72. package/dist/core/utils/sql-expressions.d.ts.map +1 -1
  73. package/dist/core/utils/sql-expressions.js +40 -0
  74. package/dist/core/utils/tuple-filter-validation.d.ts +3 -0
  75. package/dist/core/utils/tuple-filter-validation.d.ts.map +1 -0
  76. package/dist/core/utils/tuple-filter-validation.js +16 -0
  77. package/dist/index.d.ts +2 -13
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +3 -8
  80. package/dist/types/base.d.ts +89 -22
  81. package/dist/types/base.d.ts.map +1 -1
  82. package/dist/types/filters.d.ts +9 -5
  83. package/dist/types/filters.d.ts.map +1 -1
  84. package/package.json +5 -5
  85. package/dist/core/tests/integration/test-data.json +0 -190
  86. package/dist/migrations/config/index.d.ts +0 -3
  87. package/dist/migrations/config/index.d.ts.map +0 -1
  88. package/dist/migrations/config/index.js +0 -1
  89. package/dist/migrations/config/types.d.ts +0 -45
  90. package/dist/migrations/config/types.d.ts.map +0 -1
  91. package/dist/migrations/config/types.js +0 -28
  92. package/dist/migrations/diff/diff.d.ts +0 -11
  93. package/dist/migrations/diff/diff.d.ts.map +0 -1
  94. package/dist/migrations/diff/diff.js +0 -240
  95. package/dist/migrations/diff/index.d.ts +0 -3
  96. package/dist/migrations/diff/index.d.ts.map +0 -1
  97. package/dist/migrations/diff/index.js +0 -1
  98. package/dist/migrations/diff/types.d.ts +0 -74
  99. package/dist/migrations/diff/types.d.ts.map +0 -1
  100. package/dist/migrations/diff/types.js +0 -1
  101. package/dist/migrations/plan/index.d.ts +0 -3
  102. package/dist/migrations/plan/index.d.ts.map +0 -1
  103. package/dist/migrations/plan/index.js +0 -1
  104. package/dist/migrations/plan/plan.d.ts +0 -12
  105. package/dist/migrations/plan/plan.d.ts.map +0 -1
  106. package/dist/migrations/plan/plan.js +0 -416
  107. package/dist/migrations/plan/types.d.ts +0 -93
  108. package/dist/migrations/plan/types.d.ts.map +0 -1
  109. package/dist/migrations/plan/types.js +0 -1
  110. package/dist/migrations/schema/column.d.ts +0 -71
  111. package/dist/migrations/schema/column.d.ts.map +0 -1
  112. package/dist/migrations/schema/column.js +0 -123
  113. package/dist/migrations/schema/define.d.ts +0 -24
  114. package/dist/migrations/schema/define.d.ts.map +0 -1
  115. package/dist/migrations/schema/define.js +0 -47
  116. package/dist/migrations/schema/index.d.ts +0 -4
  117. package/dist/migrations/schema/index.d.ts.map +0 -1
  118. package/dist/migrations/schema/index.js +0 -2
  119. package/dist/migrations/schema/types.d.ts +0 -74
  120. package/dist/migrations/schema/types.d.ts.map +0 -1
  121. package/dist/migrations/schema/types.js +0 -1
  122. package/dist/migrations/snapshot/index.d.ts +0 -3
  123. package/dist/migrations/snapshot/index.d.ts.map +0 -1
  124. package/dist/migrations/snapshot/index.js +0 -1
  125. package/dist/migrations/snapshot/serialize.d.ts +0 -21
  126. package/dist/migrations/snapshot/serialize.d.ts.map +0 -1
  127. package/dist/migrations/snapshot/serialize.js +0 -127
  128. package/dist/migrations/snapshot/types.d.ts +0 -47
  129. package/dist/migrations/snapshot/types.d.ts.map +0 -1
  130. package/dist/migrations/snapshot/types.js +0 -1
  131. package/dist/migrations/sql/index.d.ts +0 -4
  132. package/dist/migrations/sql/index.d.ts.map +0 -1
  133. package/dist/migrations/sql/index.js +0 -2
  134. package/dist/migrations/sql/render.d.ts +0 -10
  135. package/dist/migrations/sql/render.d.ts.map +0 -1
  136. package/dist/migrations/sql/render.js +0 -347
  137. package/dist/migrations/sql/types.d.ts +0 -53
  138. package/dist/migrations/sql/types.d.ts.map +0 -1
  139. package/dist/migrations/sql/types.js +0 -1
  140. package/dist/migrations/sql/write.d.ts +0 -10
  141. package/dist/migrations/sql/write.d.ts.map +0 -1
  142. package/dist/migrations/sql/write.js +0 -35
@@ -1,190 +0,0 @@
1
- {
2
- "test_table": [
3
- {
4
- "id": 1,
5
- "name": "Product A",
6
- "category": "A",
7
- "price": 10.5,
8
- "created_at": "2023-01-01 10:00:00",
9
- "is_active": true,
10
- "tags": [
11
- "new",
12
- "sale"
13
- ],
14
- "attributes": {
15
- "color": "red",
16
- "size": "M"
17
- },
18
- "optional_note": "Popular item",
19
- "sku": "A-100",
20
- "delivery_dates": [
21
- "2023-01-05",
22
- "2023-01-10"
23
- ]
24
- },
25
- {
26
- "id": 2,
27
- "name": "Product B",
28
- "category": "B",
29
- "price": 20.75,
30
- "created_at": "2023-01-02 12:30:00",
31
- "is_active": true,
32
- "tags": [
33
- "featured"
34
- ],
35
- "attributes": {
36
- "color": "blue",
37
- "size": "L"
38
- },
39
- "optional_note": null,
40
- "sku": "B-200",
41
- "delivery_dates": [
42
- "2023-01-06"
43
- ]
44
- },
45
- {
46
- "id": 3,
47
- "name": "Product C",
48
- "category": "A",
49
- "price": 15.0,
50
- "created_at": "2023-01-03 09:45:00",
51
- "is_active": false,
52
- "tags": [],
53
- "attributes": {
54
- "color": "green",
55
- "size": "S"
56
- },
57
- "optional_note": "Backordered",
58
- "sku": "C-300",
59
- "delivery_dates": []
60
- },
61
- {
62
- "id": 4,
63
- "name": "Product D",
64
- "category": "C",
65
- "price": 8.25,
66
- "created_at": "2023-01-04 15:15:00",
67
- "is_active": true,
68
- "tags": [
69
- "clearance"
70
- ],
71
- "attributes": {
72
- "color": "yellow",
73
- "size": "XL"
74
- },
75
- "optional_note": null,
76
- "sku": "D-400",
77
- "delivery_dates": [
78
- "2023-01-08"
79
- ]
80
- },
81
- {
82
- "id": 5,
83
- "name": "Product E",
84
- "category": "B",
85
- "price": 30.0,
86
- "created_at": "2023-01-05 11:20:00",
87
- "is_active": true,
88
- "tags": [
89
- "premium",
90
- "gift"
91
- ],
92
- "attributes": {
93
- "color": "black",
94
- "size": "M"
95
- },
96
- "optional_note": "Limited stock",
97
- "sku": "E-500",
98
- "delivery_dates": [
99
- "2023-01-07",
100
- "2023-01-09"
101
- ]
102
- },
103
- {
104
- "id": 6,
105
- "name": "Product F",
106
- "category": "D",
107
- "price": 12.5,
108
- "created_at": "2023-01-06 14:40:00",
109
- "is_active": false,
110
- "tags": [],
111
- "attributes": {
112
- "color": "white",
113
- "size": "M"
114
- },
115
- "optional_note": null,
116
- "sku": "F-600",
117
- "delivery_dates": []
118
- }
119
- ],
120
- "users": [
121
- {
122
- "id": 1,
123
- "user_name": "john_doe",
124
- "email": "john@example.com",
125
- "status": "active",
126
- "created_at": "2023-01-01"
127
- },
128
- {
129
- "id": 2,
130
- "user_name": "jane_smith",
131
- "email": "jane@example.com",
132
- "status": "active",
133
- "created_at": "2023-01-02"
134
- },
135
- {
136
- "id": 3,
137
- "user_name": "bob_jones",
138
- "email": "bob@example.com",
139
- "status": "inactive",
140
- "created_at": "2023-01-03"
141
- }
142
- ],
143
- "orders": [
144
- {
145
- "id": 1,
146
- "user_id": 1,
147
- "product_id": 1,
148
- "quantity": 2,
149
- "total": 21.0,
150
- "status": "completed",
151
- "created_at": "2023-01-10"
152
- },
153
- {
154
- "id": 2,
155
- "user_id": 1,
156
- "product_id": 3,
157
- "quantity": 1,
158
- "total": 15.0,
159
- "status": "completed",
160
- "created_at": "2023-01-11"
161
- },
162
- {
163
- "id": 3,
164
- "user_id": 2,
165
- "product_id": 2,
166
- "quantity": 3,
167
- "total": 62.25,
168
- "status": "pending",
169
- "created_at": "2023-01-12"
170
- },
171
- {
172
- "id": 4,
173
- "user_id": 2,
174
- "product_id": 5,
175
- "quantity": 1,
176
- "total": 30.0,
177
- "status": "completed",
178
- "created_at": "2023-01-13"
179
- },
180
- {
181
- "id": 5,
182
- "user_id": 3,
183
- "product_id": 4,
184
- "quantity": 2,
185
- "total": 16.5,
186
- "status": "cancelled",
187
- "created_at": "2023-01-14"
188
- }
189
- ]
190
- }
@@ -1,3 +0,0 @@
1
- export { DEFAULT_MIGRATIONS_OUT_DIR, DEFAULT_MIGRATIONS_PREFIX, DEFAULT_MIGRATIONS_TABLE, defineConfig, resolveClickHouseConfig, } from './types.js';
2
- export type { ClickHouseClusterConfig, ClickHouseMigrationDbCredentials, ClickHouseMigrationDirectoryConfig, HypequeryClickHouseConfig, MigrationFilePrefix, ResolvedHypequeryClickHouseConfig, } from './types.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,YAAY,EACZ,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,uBAAuB,EACvB,gCAAgC,EAChC,kCAAkC,EAClC,yBAAyB,EACzB,mBAAmB,EACnB,iCAAiC,GAClC,MAAM,YAAY,CAAC"}
@@ -1 +0,0 @@
1
- export { DEFAULT_MIGRATIONS_OUT_DIR, DEFAULT_MIGRATIONS_PREFIX, DEFAULT_MIGRATIONS_TABLE, defineConfig, resolveClickHouseConfig, } from './types.js';
@@ -1,45 +0,0 @@
1
- export declare const DEFAULT_MIGRATIONS_OUT_DIR = "./migrations";
2
- export declare const DEFAULT_MIGRATIONS_TABLE = "_hypequery_migrations";
3
- export declare const DEFAULT_MIGRATIONS_PREFIX: "timestamp";
4
- export type MigrationFilePrefix = typeof DEFAULT_MIGRATIONS_PREFIX;
5
- export interface ClickHouseMigrationDirectoryConfig {
6
- out: string;
7
- table: string;
8
- prefix: MigrationFilePrefix;
9
- }
10
- export interface ClickHouseMigrationDbCredentials {
11
- host: string;
12
- port?: number;
13
- username: string;
14
- password?: string;
15
- database: string;
16
- secure?: boolean;
17
- }
18
- export interface ClickHouseClusterConfig {
19
- name: string;
20
- }
21
- export interface HypequeryClickHouseConfig {
22
- dialect: 'clickhouse';
23
- schema: string;
24
- migrations?: Partial<ClickHouseMigrationDirectoryConfig>;
25
- dbCredentials: ClickHouseMigrationDbCredentials;
26
- cluster?: ClickHouseClusterConfig;
27
- }
28
- export interface ResolvedHypequeryClickHouseConfig extends Omit<HypequeryClickHouseConfig, 'migrations'> {
29
- migrations: ClickHouseMigrationDirectoryConfig;
30
- }
31
- /**
32
- * Defines a ClickHouse migration configuration while preserving literal TypeScript types.
33
- *
34
- * Use this from `hypequery.config.ts` so the CLI can load database credentials,
35
- * schema entry points, and migration output settings from one typed object.
36
- */
37
- export declare function defineConfig(config: HypequeryClickHouseConfig): HypequeryClickHouseConfig;
38
- /**
39
- * Applies default migration settings to a user-provided ClickHouse config.
40
- *
41
- * This keeps CLI and programmatic callers aligned on the default output directory,
42
- * migration table name, and timestamp-based file prefix strategy.
43
- */
44
- export declare function resolveClickHouseConfig(config: HypequeryClickHouseConfig): ResolvedHypequeryClickHouseConfig;
45
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/migrations/config/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,iBAAiB,CAAC;AACzD,eAAO,MAAM,wBAAwB,0BAA0B,CAAC;AAChE,eAAO,MAAM,yBAAyB,EAAG,WAAoB,CAAC;AAE9D,MAAM,MAAM,mBAAmB,GAAG,OAAO,yBAAyB,CAAC;AAEnE,MAAM,WAAW,kCAAkC;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,mBAAmB,CAAC;CAC7B;AAED,MAAM,WAAW,gCAAgC;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC,kCAAkC,CAAC,CAAC;IACzD,aAAa,EAAE,gCAAgC,CAAC;IAChD,OAAO,CAAC,EAAE,uBAAuB,CAAC;CACnC;AAED,MAAM,WAAW,iCACf,SAAQ,IAAI,CAAC,yBAAyB,EAAE,YAAY,CAAC;IACrD,UAAU,EAAE,kCAAkC,CAAC;CAChD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,yBAAyB,GAAG,yBAAyB,CAEzF;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,yBAAyB,GAChC,iCAAiC,CASnC"}
@@ -1,28 +0,0 @@
1
- export const DEFAULT_MIGRATIONS_OUT_DIR = './migrations';
2
- export const DEFAULT_MIGRATIONS_TABLE = '_hypequery_migrations';
3
- export const DEFAULT_MIGRATIONS_PREFIX = 'timestamp';
4
- /**
5
- * Defines a ClickHouse migration configuration while preserving literal TypeScript types.
6
- *
7
- * Use this from `hypequery.config.ts` so the CLI can load database credentials,
8
- * schema entry points, and migration output settings from one typed object.
9
- */
10
- export function defineConfig(config) {
11
- return config;
12
- }
13
- /**
14
- * Applies default migration settings to a user-provided ClickHouse config.
15
- *
16
- * This keeps CLI and programmatic callers aligned on the default output directory,
17
- * migration table name, and timestamp-based file prefix strategy.
18
- */
19
- export function resolveClickHouseConfig(config) {
20
- return {
21
- ...config,
22
- migrations: {
23
- out: config.migrations?.out ?? DEFAULT_MIGRATIONS_OUT_DIR,
24
- table: config.migrations?.table ?? DEFAULT_MIGRATIONS_TABLE,
25
- prefix: config.migrations?.prefix ?? DEFAULT_MIGRATIONS_PREFIX,
26
- },
27
- };
28
- }
@@ -1,11 +0,0 @@
1
- import type { Snapshot } from '../snapshot/types.js';
2
- import type { SnapshotDiffResult } from './types.js';
3
- /**
4
- * Computes migration operations needed to move from one snapshot to another.
5
- *
6
- * The diff layer is deliberately SQL-free. It emits structured operations,
7
- * warnings for potentially expensive changes, and unsupported-change diagnostics
8
- * that the SQL renderer refuses to render automatically.
9
- */
10
- export declare function diffSnapshots(previousSnapshot: Snapshot, nextSnapshot: Snapshot): SnapshotDiffResult;
11
- //# sourceMappingURL=diff.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../../src/migrations/diff/diff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EAIT,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAQV,kBAAkB,EAGnB,MAAM,YAAY,CAAC;AAEpB;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,gBAAgB,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,GAAG,kBAAkB,CAqCpG"}
@@ -1,240 +0,0 @@
1
- /**
2
- * Computes migration operations needed to move from one snapshot to another.
3
- *
4
- * The diff layer is deliberately SQL-free. It emits structured operations,
5
- * warnings for potentially expensive changes, and unsupported-change diagnostics
6
- * that the SQL renderer refuses to render automatically.
7
- */
8
- export function diffSnapshots(previousSnapshot, nextSnapshot) {
9
- const warnings = [];
10
- const unsupportedChanges = [];
11
- const previousTables = toNameMap(previousSnapshot.tables);
12
- const nextTables = toNameMap(nextSnapshot.tables);
13
- const previousViews = toNameMap(previousSnapshot.materializedViews);
14
- const nextViews = toNameMap(nextSnapshot.materializedViews);
15
- const dropMaterializedViewOperations = diffDroppedMaterializedViews(previousViews, nextViews);
16
- const dropTableOperations = diffDroppedTables(previousTables, nextTables);
17
- const tableOperations = diffTables(previousSnapshot, nextSnapshot, previousTables, nextTables, warnings, unsupportedChanges);
18
- const createTableOperations = diffCreatedTables(previousTables, nextTables);
19
- const recreateMaterializedViewOperations = diffChangedMaterializedViews(previousViews, nextViews);
20
- const createMaterializedViewOperations = diffCreatedMaterializedViews(previousViews, nextViews);
21
- return {
22
- previousSnapshot,
23
- nextSnapshot,
24
- operations: [
25
- ...dropMaterializedViewOperations,
26
- ...dropTableOperations,
27
- ...tableOperations,
28
- ...createTableOperations,
29
- ...recreateMaterializedViewOperations,
30
- ...createMaterializedViewOperations,
31
- ],
32
- warnings,
33
- unsupportedChanges,
34
- };
35
- }
36
- function diffDroppedMaterializedViews(previousViews, nextViews) {
37
- return [...previousViews.values()]
38
- .filter(view => !nextViews.has(view.name))
39
- .map(view => ({
40
- kind: 'DropMaterializedView',
41
- viewName: view.name,
42
- }));
43
- }
44
- function diffDroppedTables(previousTables, nextTables) {
45
- return [...previousTables.values()]
46
- .filter(table => !nextTables.has(table.name))
47
- .map(table => ({
48
- kind: 'DropTable',
49
- tableName: table.name,
50
- }));
51
- }
52
- function diffCreatedTables(previousTables, nextTables) {
53
- return [...nextTables.values()]
54
- .filter(table => !previousTables.has(table.name))
55
- .map(table => ({
56
- kind: 'CreateTable',
57
- table,
58
- }));
59
- }
60
- function diffCreatedMaterializedViews(previousViews, nextViews) {
61
- return [...nextViews.values()]
62
- .filter(view => !previousViews.has(view.name))
63
- .map(view => ({
64
- kind: 'CreateMaterializedView',
65
- view,
66
- }));
67
- }
68
- function diffChangedMaterializedViews(previousViews, nextViews) {
69
- const operations = [];
70
- for (const previousView of previousViews.values()) {
71
- const nextView = nextViews.get(previousView.name);
72
- if (!nextView) {
73
- continue;
74
- }
75
- if (!isSameMaterializedView(previousView, nextView)) {
76
- operations.push({
77
- kind: 'RecreateMaterializedView',
78
- previousView,
79
- nextView,
80
- });
81
- }
82
- }
83
- return operations;
84
- }
85
- function diffTables(previousSnapshot, nextSnapshot, previousTables, nextTables, warnings, unsupportedChanges) {
86
- const operations = [];
87
- for (const previousTable of previousTables.values()) {
88
- const nextTable = nextTables.get(previousTable.name);
89
- if (!nextTable) {
90
- continue;
91
- }
92
- if (!isSameTableEngine(previousTable.engine, nextTable.engine)) {
93
- unsupportedChanges.push({
94
- kind: 'TableEngineChanged',
95
- tableName: previousTable.name,
96
- message: `Table engine changed for "${previousTable.name}". Engine evolution is not auto-generated yet.`,
97
- });
98
- }
99
- if (!isSameSettings(previousTable.settings, nextTable.settings)) {
100
- unsupportedChanges.push({
101
- kind: 'TableSettingsChanged',
102
- tableName: previousTable.name,
103
- message: `Table settings changed for "${previousTable.name}". Settings diffs are not auto-generated yet.`,
104
- });
105
- }
106
- const tableMutations = diffColumns(previousTable, nextTable, warnings, unsupportedChanges);
107
- if (tableMutations.length === 0) {
108
- continue;
109
- }
110
- const dependentViewNames = getDependentViewNames(previousSnapshot, nextSnapshot, previousTable.name);
111
- if (dependentViewNames.length > 0) {
112
- operations.push({
113
- kind: 'AlterTableWithDependentViews',
114
- tableName: previousTable.name,
115
- dependentViewNames,
116
- operations: tableMutations,
117
- });
118
- continue;
119
- }
120
- operations.push(...tableMutations);
121
- }
122
- return operations;
123
- }
124
- function diffColumns(previousTable, nextTable, warnings, unsupportedChanges) {
125
- const operations = [];
126
- const previousColumns = toNameMap(previousTable.columns);
127
- const nextColumns = toNameMap(nextTable.columns);
128
- const droppedColumns = [...previousColumns.values()].filter(column => !nextColumns.has(column.name));
129
- const addedColumns = [...nextColumns.values()].filter(column => !previousColumns.has(column.name));
130
- detectPossibleRenames(previousTable.name, droppedColumns, addedColumns, unsupportedChanges);
131
- for (const column of droppedColumns) {
132
- operations.push({
133
- kind: 'DropColumn',
134
- tableName: previousTable.name,
135
- columnName: column.name,
136
- });
137
- }
138
- for (const column of addedColumns) {
139
- operations.push({
140
- kind: 'AddColumn',
141
- tableName: previousTable.name,
142
- column,
143
- });
144
- }
145
- for (const previousColumn of previousColumns.values()) {
146
- const nextColumn = nextColumns.get(previousColumn.name);
147
- if (!nextColumn) {
148
- continue;
149
- }
150
- if (previousColumn.type !== nextColumn.type) {
151
- operations.push({
152
- kind: 'ModifyColumnType',
153
- tableName: previousTable.name,
154
- columnName: previousColumn.name,
155
- previousType: previousColumn.type,
156
- nextType: nextColumn.type,
157
- });
158
- warnings.push({
159
- kind: 'ModifyColumnTypeRequiresConfirmation',
160
- tableName: previousTable.name,
161
- columnName: previousColumn.name,
162
- message: `Column type changed for "${previousTable.name}.${previousColumn.name}" ` +
163
- `from "${previousColumn.type}" to "${nextColumn.type}".`,
164
- });
165
- }
166
- if (!isSameColumnDefault(previousColumn.default, nextColumn.default)) {
167
- operations.push({
168
- kind: 'ModifyColumnDefault',
169
- tableName: previousTable.name,
170
- columnName: previousColumn.name,
171
- previousDefault: previousColumn.default,
172
- nextDefault: nextColumn.default,
173
- });
174
- }
175
- }
176
- return operations;
177
- }
178
- function isSameColumnDefault(left, right) {
179
- if (left === right) {
180
- return true;
181
- }
182
- if (left === undefined || right === undefined) {
183
- return false;
184
- }
185
- return left.kind === right.kind && left.value === right.value;
186
- }
187
- function detectPossibleRenames(tableName, droppedColumns, addedColumns, unsupportedChanges) {
188
- for (const droppedColumn of droppedColumns) {
189
- const renameCandidate = addedColumns.find(addedColumn => addedColumn.type === droppedColumn.type &&
190
- isSameColumnDefault(addedColumn.default, droppedColumn.default));
191
- if (!renameCandidate) {
192
- continue;
193
- }
194
- unsupportedChanges.push({
195
- kind: 'PossibleColumnRename',
196
- tableName,
197
- columnName: droppedColumn.name,
198
- message: `Possible column rename detected in "${tableName}": ` +
199
- `"${droppedColumn.name}" -> "${renameCandidate.name}". ` +
200
- `Rename inference is not supported in generated migrations.`,
201
- });
202
- }
203
- }
204
- function getDependentViewNames(previousSnapshot, nextSnapshot, tableName) {
205
- return [...new Set([
206
- ...previousSnapshot.dependencies
207
- .filter(edge => edge.kind === 'table_to_materialized_view' && edge.from === tableName)
208
- .map(edge => edge.to),
209
- ...nextSnapshot.dependencies
210
- .filter(edge => edge.kind === 'table_to_materialized_view' && edge.from === tableName)
211
- .map(edge => edge.to),
212
- ])].sort((left, right) => left.localeCompare(right));
213
- }
214
- function isSameTableEngine(left, right) {
215
- return left.type === right.type &&
216
- isSameStringArray(left.orderBy, right.orderBy) &&
217
- (left.partitionBy ?? null) === (right.partitionBy ?? null) &&
218
- isSameStringArray(left.primaryKey, right.primaryKey) &&
219
- (left.sampleBy ?? null) === (right.sampleBy ?? null);
220
- }
221
- function isSameSettings(left, right) {
222
- const leftEntries = Object.entries(left);
223
- const rightEntries = Object.entries(right);
224
- if (leftEntries.length !== rightEntries.length) {
225
- return false;
226
- }
227
- return leftEntries.every(([key, value]) => right[key] === value);
228
- }
229
- function isSameMaterializedView(left, right) {
230
- return left.name === right.name &&
231
- left.from === right.from &&
232
- (left.to ?? null) === (right.to ?? null) &&
233
- left.select === right.select;
234
- }
235
- function isSameStringArray(left, right) {
236
- return left.length === right.length && left.every((value, index) => value === right[index]);
237
- }
238
- function toNameMap(entries) {
239
- return new Map(entries.map(entry => [entry.name, entry]));
240
- }
@@ -1,3 +0,0 @@
1
- export { diffSnapshots } from './diff.js';
2
- export type { AddColumnOperation, AlterTableWithDependentViewsOperation, CreateMaterializedViewOperation, CreateTableOperation, DiffWarning, DropColumnOperation, DropMaterializedViewOperation, DropTableOperation, MigrationOperation, ModifyColumnDefaultOperation, ModifyColumnTypeOperation, RecreateMaterializedViewOperation, SnapshotDiffResult, TableMutationOperation, UnsupportedChange, } from './types.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/diff/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,YAAY,EACV,kBAAkB,EAClB,qCAAqC,EACrC,+BAA+B,EAC/B,oBAAoB,EACpB,WAAW,EACX,mBAAmB,EACnB,6BAA6B,EAC7B,kBAAkB,EAClB,kBAAkB,EAClB,4BAA4B,EAC5B,yBAAyB,EACzB,iCAAiC,EACjC,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
@@ -1 +0,0 @@
1
- export { diffSnapshots } from './diff.js';
@@ -1,74 +0,0 @@
1
- import type { Snapshot, SnapshotColumn, SnapshotColumnDefault, SnapshotMaterializedView, SnapshotTable } from '../snapshot/types.js';
2
- export interface CreateTableOperation {
3
- kind: 'CreateTable';
4
- table: SnapshotTable;
5
- }
6
- export interface DropTableOperation {
7
- kind: 'DropTable';
8
- tableName: string;
9
- }
10
- export interface AddColumnOperation {
11
- kind: 'AddColumn';
12
- tableName: string;
13
- column: SnapshotColumn;
14
- }
15
- export interface DropColumnOperation {
16
- kind: 'DropColumn';
17
- tableName: string;
18
- columnName: string;
19
- }
20
- export interface ModifyColumnDefaultOperation {
21
- kind: 'ModifyColumnDefault';
22
- tableName: string;
23
- columnName: string;
24
- previousDefault?: SnapshotColumnDefault;
25
- nextDefault?: SnapshotColumnDefault;
26
- }
27
- export interface ModifyColumnTypeOperation {
28
- kind: 'ModifyColumnType';
29
- tableName: string;
30
- columnName: string;
31
- previousType: string;
32
- nextType: string;
33
- }
34
- export interface CreateMaterializedViewOperation {
35
- kind: 'CreateMaterializedView';
36
- view: SnapshotMaterializedView;
37
- }
38
- export interface DropMaterializedViewOperation {
39
- kind: 'DropMaterializedView';
40
- viewName: string;
41
- }
42
- export interface RecreateMaterializedViewOperation {
43
- kind: 'RecreateMaterializedView';
44
- previousView: SnapshotMaterializedView;
45
- nextView: SnapshotMaterializedView;
46
- }
47
- export type TableMutationOperation = AddColumnOperation | DropColumnOperation | ModifyColumnDefaultOperation | ModifyColumnTypeOperation;
48
- export interface AlterTableWithDependentViewsOperation {
49
- kind: 'AlterTableWithDependentViews';
50
- tableName: string;
51
- dependentViewNames: string[];
52
- operations: TableMutationOperation[];
53
- }
54
- export type MigrationOperation = AlterTableWithDependentViewsOperation | CreateMaterializedViewOperation | CreateTableOperation | DropMaterializedViewOperation | DropTableOperation | RecreateMaterializedViewOperation | TableMutationOperation;
55
- export interface DiffWarning {
56
- kind: 'ModifyColumnTypeRequiresConfirmation';
57
- tableName: string;
58
- columnName: string;
59
- message: string;
60
- }
61
- export interface UnsupportedChange {
62
- kind: 'PossibleColumnRename' | 'TableEngineChanged' | 'TableSettingsChanged';
63
- message: string;
64
- tableName: string;
65
- columnName?: string;
66
- }
67
- export interface SnapshotDiffResult {
68
- previousSnapshot: Snapshot;
69
- nextSnapshot: Snapshot;
70
- operations: MigrationOperation[];
71
- warnings: DiffWarning[];
72
- unsupportedChanges: UnsupportedChange[];
73
- }
74
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/migrations/diff/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EACd,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EACd,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,aAAa,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,cAAc,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE,qBAAqB,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,qBAAqB,CAAC;IACxC,WAAW,CAAC,EAAE,qBAAqB,CAAC;CACrC;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,kBAAkB,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,+BAA+B;IAC9C,IAAI,EAAE,wBAAwB,CAAC;IAC/B,IAAI,EAAE,wBAAwB,CAAC;CAChC;AAED,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,sBAAsB,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,0BAA0B,CAAC;IACjC,YAAY,EAAE,wBAAwB,CAAC;IACvC,QAAQ,EAAE,wBAAwB,CAAC;CACpC;AAED,MAAM,MAAM,sBAAsB,GAC9B,kBAAkB,GAClB,mBAAmB,GACnB,4BAA4B,GAC5B,yBAAyB,CAAC;AAE9B,MAAM,WAAW,qCAAqC;IACpD,IAAI,EAAE,8BAA8B,CAAC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,UAAU,EAAE,sBAAsB,EAAE,CAAC;CACtC;AAED,MAAM,MAAM,kBAAkB,GAC1B,qCAAqC,GACrC,+BAA+B,GAC/B,oBAAoB,GACpB,6BAA6B,GAC7B,kBAAkB,GAClB,iCAAiC,GACjC,sBAAsB,CAAC;AAE3B,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,sCAAsC,CAAC;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EACA,sBAAsB,GACtB,oBAAoB,GACpB,sBAAsB,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,gBAAgB,EAAE,QAAQ,CAAC;IAC3B,YAAY,EAAE,QAAQ,CAAC;IACvB,UAAU,EAAE,kBAAkB,EAAE,CAAC;IACjC,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;CACzC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- export { createMigrationPlan, isMigrationPlan } from './plan.js';
2
- export type { ClickHouseMigrationSyncSetting, ClickHouseMigrationPlanContext, ClickHouseTableCostStats, CreateMigrationPlanOptions, MigrationPlanAnalyzer, MigrationPlanAnalyzerContext, MigrationPlanAnalyzerResult, MigrationOperationClassification, MigrationOperationCostEstimate, MigrationPlan, MigrationPlanBlocker, MigrationPlanConfirmation, MigrationPlanDiagnostic, MigrationPlanDiagnosticLevel, MigrationPlanInput, PlannedMigrationOperation, } from './types.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/plan/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjE,YAAY,EACV,8BAA8B,EAC9B,8BAA8B,EAC9B,wBAAwB,EACxB,0BAA0B,EAC1B,qBAAqB,EACrB,4BAA4B,EAC5B,2BAA2B,EAC3B,gCAAgC,EAChC,8BAA8B,EAC9B,aAAa,EACb,oBAAoB,EACpB,yBAAyB,EACzB,uBAAuB,EACvB,4BAA4B,EAC5B,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,YAAY,CAAC"}
@@ -1 +0,0 @@
1
- export { createMigrationPlan, isMigrationPlan } from './plan.js';
@@ -1,12 +0,0 @@
1
- import type { SnapshotDiffResult } from '../diff/types.js';
2
- import type { CreateMigrationPlanOptions, MigrationPlan, MigrationPlanInput } from './types.js';
3
- /**
4
- * Converts a raw snapshot diff into an explicit migration plan.
5
- *
6
- * The initial planner is intentionally static: it classifies operations and
7
- * carries diagnostics/blockers without querying a live ClickHouse instance.
8
- * Later phases can enrich this plan with system-table cost estimates.
9
- */
10
- export declare function createMigrationPlan(diff: SnapshotDiffResult, options?: CreateMigrationPlanOptions): MigrationPlan;
11
- export declare function isMigrationPlan(input: MigrationPlanInput): input is MigrationPlan;
12
- //# sourceMappingURL=plan.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../../src/migrations/plan/plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,kBAAkB,EAEnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAIV,0BAA0B,EAG1B,aAAa,EAMb,kBAAkB,EAEnB,MAAM,YAAY,CAAC;AAEpB;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,kBAAkB,EACxB,OAAO,GAAE,0BAA+B,GACvC,aAAa,CAqFf;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,kBAAkB,GAAG,KAAK,IAAI,aAAa,CAMjF"}