@effectstream/db 0.100.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/assets-config.json +28 -0
- package/migrations/assets.ts +35 -0
- package/migrations/readme.md +37 -0
- package/migrations/system-down-v-0.0.0.sql +2 -0
- package/migrations/system-down-v-0.0.1.sql +14 -0
- package/migrations/system-up-v-0.0.0.sql +40 -0
- package/migrations/system-up-v-0.0.1.sql +117 -0
- package/migrations/system-up-v-0.0.2.sql +22 -0
- package/migrations/system-up-v-0.8.1.sql +5 -0
- package/migrations/system-version.ts +147 -0
- package/package.json +33 -0
- package/pgtypedconfig.json +21 -0
- package/scripts/Dockerfile +13 -0
- package/scripts/apply-migrations.ts +49 -0
- package/scripts/pgtyped-internal.ts +43 -0
- package/scripts/pgtyped-update.ts +119 -0
- package/scripts/start-pglite.ts +71 -0
- package/scripts/wait-for-db.ts +43 -0
- package/src/dynamic-tables.ts +110 -0
- package/src/event-indexing.ts +31 -0
- package/src/migrations.ts +28 -0
- package/src/mod.ts +65 -0
- package/src/pg-connection.test.ts +99 -0
- package/src/pg-connection.ts +211 -0
- package/src/register-events.ts +40 -0
- package/src/scheduled-constructors.ts +117 -0
- package/src/snapshot-handler.ts +164 -0
- package/src/sql/accounts.queries.ts +350 -0
- package/src/sql/accounts.sql +77 -0
- package/src/sql/achievements.queries.ts +74 -0
- package/src/sql/achievements.sql +17 -0
- package/src/sql/block-heights.queries.ts +205 -0
- package/src/sql/block-heights.sql +45 -0
- package/src/sql/events.queries.ts +201 -0
- package/src/sql/events.sql +41 -0
- package/src/sql/nonces.queries.ts +85 -0
- package/src/sql/nonces.sql +11 -0
- package/src/sql/primitives.queries.ts +35 -0
- package/src/sql/primitives.sql +4 -0
- package/src/sql/rollup_inputs.queries.ts +654 -0
- package/src/sql/rollup_inputs.sql +227 -0
- package/src/sql/statistics.queries.ts +160 -0
- package/src/sql/statistics.sql +55 -0
- package/src/sql/sync-protocols/page.queries.ts +140 -0
- package/src/sql/sync-protocols/page.sql +39 -0
- package/src/sql/system.queries.ts +356 -0
- package/src/sql/system.sql +75 -0
- package/src/sql/tables.queries.ts +89 -0
- package/src/sql/tables.sql +17 -0
- package/src/system.ts +41 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/** Types generated for queries found in "src/sql/system.sql" */
|
|
2
|
+
import { PreparedQuery } from '@pgtyped/runtime';
|
|
3
|
+
|
|
4
|
+
export type Json = null | boolean | number | string | Json[] | { [key: string]: Json };
|
|
5
|
+
|
|
6
|
+
/** 'GetTableSchema' parameters type */
|
|
7
|
+
export interface IGetTableSchemaParams {
|
|
8
|
+
tableName: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** 'GetTableSchema' return type */
|
|
12
|
+
export interface IGetTableSchemaResult {
|
|
13
|
+
character_maximum_length: number | null;
|
|
14
|
+
column_default: string | null;
|
|
15
|
+
column_name: string | null;
|
|
16
|
+
data_type: string | null;
|
|
17
|
+
is_nullable: string | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** 'GetTableSchema' query type */
|
|
21
|
+
export interface IGetTableSchemaQuery {
|
|
22
|
+
params: IGetTableSchemaParams;
|
|
23
|
+
result: IGetTableSchemaResult;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const getTableSchemaIR: any = {"usedParamSet":{"tableName":true},"params":[{"name":"tableName","required":true,"transform":{"type":"scalar"},"locs":[{"a":140,"b":150}]}],"statement":"SELECT \ncolumn_name, data_type, character_maximum_length, column_default, is_nullable\nFROM \nINFORMATION_SCHEMA.COLUMNS \nWHERE \ntable_name = :tableName!"};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Query generated from SQL:
|
|
30
|
+
* ```
|
|
31
|
+
* SELECT
|
|
32
|
+
* column_name, data_type, character_maximum_length, column_default, is_nullable
|
|
33
|
+
* FROM
|
|
34
|
+
* INFORMATION_SCHEMA.COLUMNS
|
|
35
|
+
* WHERE
|
|
36
|
+
* table_name = :tableName!
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export const getTableSchema = new PreparedQuery<IGetTableSchemaParams,IGetTableSchemaResult>(getTableSchemaIR);
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/** 'GetLatestVersion' parameters type */
|
|
43
|
+
export type IGetLatestVersionParams = void;
|
|
44
|
+
|
|
45
|
+
/** 'GetLatestVersion' return type */
|
|
46
|
+
export interface IGetLatestVersionResult {
|
|
47
|
+
app_version_major: number;
|
|
48
|
+
app_version_minor: number;
|
|
49
|
+
app_version_patch: number;
|
|
50
|
+
block_height: number;
|
|
51
|
+
engine_version_major: number;
|
|
52
|
+
engine_version_minor: number;
|
|
53
|
+
engine_version_patch: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 'GetLatestVersion' query type */
|
|
57
|
+
export interface IGetLatestVersionQuery {
|
|
58
|
+
params: IGetLatestVersionParams;
|
|
59
|
+
result: IGetLatestVersionResult;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const getLatestVersionIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT \napp_version_major, app_version_minor, app_version_patch, engine_version_major, engine_version_minor, engine_version_patch, block_height\nFROM \neffectstream.effectstream_version_history\nORDER BY block_height DESC\nLIMIT 1"};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Query generated from SQL:
|
|
66
|
+
* ```
|
|
67
|
+
* SELECT
|
|
68
|
+
* app_version_major, app_version_minor, app_version_patch, engine_version_major, engine_version_minor, engine_version_patch, block_height
|
|
69
|
+
* FROM
|
|
70
|
+
* effectstream.effectstream_version_history
|
|
71
|
+
* ORDER BY block_height DESC
|
|
72
|
+
* LIMIT 1
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export const getLatestVersion = new PreparedQuery<IGetLatestVersionParams,IGetLatestVersionResult>(getLatestVersionIR);
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/** 'TableExists' parameters type */
|
|
79
|
+
export type ITableExistsParams = void;
|
|
80
|
+
|
|
81
|
+
/** 'TableExists' return type */
|
|
82
|
+
export interface ITableExistsResult {
|
|
83
|
+
exists: boolean | null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** 'TableExists' query type */
|
|
87
|
+
export interface ITableExistsQuery {
|
|
88
|
+
params: ITableExistsParams;
|
|
89
|
+
result: ITableExistsResult;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const tableExistsIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT EXISTS (\n SELECT FROM information_schema.tables \n WHERE table_schema = 'effectstream'\n AND table_name = 'effectstream_version_history'\n)"};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Query generated from SQL:
|
|
96
|
+
* ```
|
|
97
|
+
* SELECT EXISTS (
|
|
98
|
+
* SELECT FROM information_schema.tables
|
|
99
|
+
* WHERE table_schema = 'effectstream'
|
|
100
|
+
* AND table_name = 'effectstream_version_history'
|
|
101
|
+
* )
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export const tableExists = new PreparedQuery<ITableExistsParams,ITableExistsResult>(tableExistsIR);
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
/** 'InsertPaimaEngineMigration' parameters type */
|
|
108
|
+
export interface IInsertPaimaEngineMigrationParams {
|
|
109
|
+
blockHeight: number;
|
|
110
|
+
isSystemMigration: boolean;
|
|
111
|
+
name: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 'InsertPaimaEngineMigration' return type */
|
|
115
|
+
export type IInsertPaimaEngineMigrationResult = void;
|
|
116
|
+
|
|
117
|
+
/** 'InsertPaimaEngineMigration' query type */
|
|
118
|
+
export interface IInsertPaimaEngineMigrationQuery {
|
|
119
|
+
params: IInsertPaimaEngineMigrationParams;
|
|
120
|
+
result: IInsertPaimaEngineMigrationResult;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const insertPaimaEngineMigrationIR: any = {"usedParamSet":{"name":true,"blockHeight":true,"isSystemMigration":true},"params":[{"name":"name","required":true,"transform":{"type":"scalar"},"locs":[{"a":109,"b":114}]},{"name":"blockHeight","required":true,"transform":{"type":"scalar"},"locs":[{"a":117,"b":129}]},{"name":"isSystemMigration","required":true,"transform":{"type":"scalar"},"locs":[{"a":132,"b":150}]}],"statement":"INSERT INTO effectstream.effectstream_migration_history \n(name, block_height, is_system_migration) \nVALUES \n(:name!, :blockHeight!, :isSystemMigration!)"};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Query generated from SQL:
|
|
127
|
+
* ```
|
|
128
|
+
* INSERT INTO effectstream.effectstream_migration_history
|
|
129
|
+
* (name, block_height, is_system_migration)
|
|
130
|
+
* VALUES
|
|
131
|
+
* (:name!, :blockHeight!, :isSystemMigration!)
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export const insertPaimaEngineMigration = new PreparedQuery<IInsertPaimaEngineMigrationParams,IInsertPaimaEngineMigrationResult>(insertPaimaEngineMigrationIR);
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
/** 'InsertPaimaEngineVersion' parameters type */
|
|
138
|
+
export interface IInsertPaimaEngineVersionParams {
|
|
139
|
+
appVersionMajor: number;
|
|
140
|
+
appVersionMinor: number;
|
|
141
|
+
appVersionPatch: number;
|
|
142
|
+
blockHeight: number;
|
|
143
|
+
engineVersionMajor: number;
|
|
144
|
+
engineVersionMinor: number;
|
|
145
|
+
engineVersionPatch: number;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** 'InsertPaimaEngineVersion' return type */
|
|
149
|
+
export type IInsertPaimaEngineVersionResult = void;
|
|
150
|
+
|
|
151
|
+
/** 'InsertPaimaEngineVersion' query type */
|
|
152
|
+
export interface IInsertPaimaEngineVersionQuery {
|
|
153
|
+
params: IInsertPaimaEngineVersionParams;
|
|
154
|
+
result: IInsertPaimaEngineVersionResult;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const insertPaimaEngineVersionIR: any = {"usedParamSet":{"appVersionMajor":true,"appVersionMinor":true,"appVersionPatch":true,"engineVersionMajor":true,"engineVersionMinor":true,"engineVersionPatch":true,"blockHeight":true},"params":[{"name":"appVersionMajor","required":true,"transform":{"type":"scalar"},"locs":[{"a":203,"b":219}]},{"name":"appVersionMinor","required":true,"transform":{"type":"scalar"},"locs":[{"a":222,"b":238}]},{"name":"appVersionPatch","required":true,"transform":{"type":"scalar"},"locs":[{"a":241,"b":257}]},{"name":"engineVersionMajor","required":true,"transform":{"type":"scalar"},"locs":[{"a":260,"b":279}]},{"name":"engineVersionMinor","required":true,"transform":{"type":"scalar"},"locs":[{"a":282,"b":301}]},{"name":"engineVersionPatch","required":true,"transform":{"type":"scalar"},"locs":[{"a":304,"b":323}]},{"name":"blockHeight","required":true,"transform":{"type":"scalar"},"locs":[{"a":326,"b":338}]}],"statement":"INSERT INTO effectstream.effectstream_version_history \n(app_version_major, app_version_minor, app_version_patch, engine_version_major, engine_version_minor, engine_version_patch, block_height) \nVALUES \n(:appVersionMajor!, :appVersionMinor!, :appVersionPatch!, :engineVersionMajor!, :engineVersionMinor!, :engineVersionPatch!, :blockHeight!)"};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Query generated from SQL:
|
|
161
|
+
* ```
|
|
162
|
+
* INSERT INTO effectstream.effectstream_version_history
|
|
163
|
+
* (app_version_major, app_version_minor, app_version_patch, engine_version_major, engine_version_minor, engine_version_patch, block_height)
|
|
164
|
+
* VALUES
|
|
165
|
+
* (:appVersionMajor!, :appVersionMinor!, :appVersionPatch!, :engineVersionMajor!, :engineVersionMinor!, :engineVersionPatch!, :blockHeight!)
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export const insertPaimaEngineVersion = new PreparedQuery<IInsertPaimaEngineVersionParams,IInsertPaimaEngineVersionResult>(insertPaimaEngineVersionIR);
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
/** 'FindMigrationByName' parameters type */
|
|
172
|
+
export interface IFindMigrationByNameParams {
|
|
173
|
+
isSystemMigration: boolean;
|
|
174
|
+
name: string;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** 'FindMigrationByName' return type */
|
|
178
|
+
export interface IFindMigrationByNameResult {
|
|
179
|
+
block_height: number;
|
|
180
|
+
is_system_migration: boolean;
|
|
181
|
+
name: string;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** 'FindMigrationByName' query type */
|
|
185
|
+
export interface IFindMigrationByNameQuery {
|
|
186
|
+
params: IFindMigrationByNameParams;
|
|
187
|
+
result: IFindMigrationByNameResult;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const findMigrationByNameIR: any = {"usedParamSet":{"name":true,"isSystemMigration":true},"params":[{"name":"name","required":true,"transform":{"type":"scalar"},"locs":[{"a":71,"b":76}]},{"name":"isSystemMigration","required":true,"transform":{"type":"scalar"},"locs":[{"a":104,"b":122}]}],"statement":"SELECT * FROM effectstream.effectstream_migration_history\nWHERE name = :name!\nAND is_system_migration = :isSystemMigration!"};
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Query generated from SQL:
|
|
194
|
+
* ```
|
|
195
|
+
* SELECT * FROM effectstream.effectstream_migration_history
|
|
196
|
+
* WHERE name = :name!
|
|
197
|
+
* AND is_system_migration = :isSystemMigration!
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export const findMigrationByName = new PreparedQuery<IFindMigrationByNameParams,IFindMigrationByNameResult>(findMigrationByNameIR);
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
/** 'InsertEngineExpectedVersion' parameters type */
|
|
204
|
+
export interface IInsertEngineExpectedVersionParams {
|
|
205
|
+
appVersionMajor: number;
|
|
206
|
+
appVersionMinor: number;
|
|
207
|
+
appVersionPatch: number;
|
|
208
|
+
blockHeight: number;
|
|
209
|
+
engineVersionMajor: number;
|
|
210
|
+
engineVersionMinor: number;
|
|
211
|
+
engineVersionPatch: number;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** 'InsertEngineExpectedVersion' return type */
|
|
215
|
+
export type IInsertEngineExpectedVersionResult = void;
|
|
216
|
+
|
|
217
|
+
/** 'InsertEngineExpectedVersion' query type */
|
|
218
|
+
export interface IInsertEngineExpectedVersionQuery {
|
|
219
|
+
params: IInsertEngineExpectedVersionParams;
|
|
220
|
+
result: IInsertEngineExpectedVersionResult;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const insertEngineExpectedVersionIR: any = {"usedParamSet":{"appVersionMajor":true,"appVersionMinor":true,"appVersionPatch":true,"engineVersionMajor":true,"engineVersionMinor":true,"engineVersionPatch":true,"blockHeight":true},"params":[{"name":"appVersionMajor","required":true,"transform":{"type":"scalar"},"locs":[{"a":204,"b":220}]},{"name":"appVersionMinor","required":true,"transform":{"type":"scalar"},"locs":[{"a":223,"b":239}]},{"name":"appVersionPatch","required":true,"transform":{"type":"scalar"},"locs":[{"a":242,"b":258}]},{"name":"engineVersionMajor","required":true,"transform":{"type":"scalar"},"locs":[{"a":261,"b":280}]},{"name":"engineVersionMinor","required":true,"transform":{"type":"scalar"},"locs":[{"a":283,"b":302}]},{"name":"engineVersionPatch","required":true,"transform":{"type":"scalar"},"locs":[{"a":305,"b":324}]},{"name":"blockHeight","required":true,"transform":{"type":"scalar"},"locs":[{"a":327,"b":339}]}],"statement":"INSERT INTO effectstream.effectstream_expected_version \n(app_version_major, app_version_minor, app_version_patch, engine_version_major, engine_version_minor, engine_version_patch, block_height) \nVALUES \n(:appVersionMajor!, :appVersionMinor!, :appVersionPatch!, :engineVersionMajor!, :engineVersionMinor!, :engineVersionPatch!, :blockHeight!)"};
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Query generated from SQL:
|
|
227
|
+
* ```
|
|
228
|
+
* INSERT INTO effectstream.effectstream_expected_version
|
|
229
|
+
* (app_version_major, app_version_minor, app_version_patch, engine_version_major, engine_version_minor, engine_version_patch, block_height)
|
|
230
|
+
* VALUES
|
|
231
|
+
* (:appVersionMajor!, :appVersionMinor!, :appVersionPatch!, :engineVersionMajor!, :engineVersionMinor!, :engineVersionPatch!, :blockHeight!)
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
export const insertEngineExpectedVersion = new PreparedQuery<IInsertEngineExpectedVersionParams,IInsertEngineExpectedVersionResult>(insertEngineExpectedVersionIR);
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
/** 'GetExpectedEngineVersion' parameters type */
|
|
238
|
+
export type IGetExpectedEngineVersionParams = void;
|
|
239
|
+
|
|
240
|
+
/** 'GetExpectedEngineVersion' return type */
|
|
241
|
+
export interface IGetExpectedEngineVersionResult {
|
|
242
|
+
app_version_major: number;
|
|
243
|
+
app_version_minor: number;
|
|
244
|
+
app_version_patch: number;
|
|
245
|
+
block_height: number;
|
|
246
|
+
engine_version_major: number;
|
|
247
|
+
engine_version_minor: number;
|
|
248
|
+
engine_version_patch: number;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** 'GetExpectedEngineVersion' query type */
|
|
252
|
+
export interface IGetExpectedEngineVersionQuery {
|
|
253
|
+
params: IGetExpectedEngineVersionParams;
|
|
254
|
+
result: IGetExpectedEngineVersionResult;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const getExpectedEngineVersionIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT * FROM effectstream.effectstream_expected_version\nORDER BY block_height DESC\nLIMIT 1"};
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Query generated from SQL:
|
|
261
|
+
* ```
|
|
262
|
+
* SELECT * FROM effectstream.effectstream_expected_version
|
|
263
|
+
* ORDER BY block_height DESC
|
|
264
|
+
* LIMIT 1
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
export const getExpectedEngineVersion = new PreparedQuery<IGetExpectedEngineVersionParams,IGetExpectedEngineVersionResult>(getExpectedEngineVersionIR);
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
/** 'GetAllTableNames' parameters type */
|
|
271
|
+
export type IGetAllTableNamesParams = void;
|
|
272
|
+
|
|
273
|
+
/** 'GetAllTableNames' return type */
|
|
274
|
+
export interface IGetAllTableNamesResult {
|
|
275
|
+
tablename: string | null;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** 'GetAllTableNames' query type */
|
|
279
|
+
export interface IGetAllTableNamesQuery {
|
|
280
|
+
params: IGetAllTableNamesParams;
|
|
281
|
+
result: IGetAllTableNamesResult;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const getAllTableNamesIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT tablename\nFROM pg_tables\nWHERE schemaname = 'public'"};
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Query generated from SQL:
|
|
288
|
+
* ```
|
|
289
|
+
* SELECT tablename
|
|
290
|
+
* FROM pg_tables
|
|
291
|
+
* WHERE schemaname = 'public'
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
export const getAllTableNames = new PreparedQuery<IGetAllTableNamesParams,IGetAllTableNamesResult>(getAllTableNamesIR);
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
/** 'UpsertSyncProtocolConfigSnapshot' parameters type */
|
|
298
|
+
export interface IUpsertSyncProtocolConfigSnapshotParams {
|
|
299
|
+
immutableConfig: Json;
|
|
300
|
+
networkType: string;
|
|
301
|
+
protocolName: string;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** 'UpsertSyncProtocolConfigSnapshot' return type */
|
|
305
|
+
export type IUpsertSyncProtocolConfigSnapshotResult = void;
|
|
306
|
+
|
|
307
|
+
/** 'UpsertSyncProtocolConfigSnapshot' query type */
|
|
308
|
+
export interface IUpsertSyncProtocolConfigSnapshotQuery {
|
|
309
|
+
params: IUpsertSyncProtocolConfigSnapshotParams;
|
|
310
|
+
result: IUpsertSyncProtocolConfigSnapshotResult;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const upsertSyncProtocolConfigSnapshotIR: any = {"usedParamSet":{"protocolName":true,"networkType":true,"immutableConfig":true},"params":[{"name":"protocolName","required":true,"transform":{"type":"scalar"},"locs":[{"a":111,"b":124}]},{"name":"networkType","required":true,"transform":{"type":"scalar"},"locs":[{"a":127,"b":139}]},{"name":"immutableConfig","required":true,"transform":{"type":"scalar"},"locs":[{"a":142,"b":158}]}],"statement":"INSERT INTO effectstream.sync_protocol_config_snapshot (protocol_name, network_type, immutable_config)\nVALUES (:protocolName!, :networkType!, :immutableConfig!)\nON CONFLICT (protocol_name) DO NOTHING"};
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Query generated from SQL:
|
|
317
|
+
* ```
|
|
318
|
+
* INSERT INTO effectstream.sync_protocol_config_snapshot (protocol_name, network_type, immutable_config)
|
|
319
|
+
* VALUES (:protocolName!, :networkType!, :immutableConfig!)
|
|
320
|
+
* ON CONFLICT (protocol_name) DO NOTHING
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
export const upsertSyncProtocolConfigSnapshot = new PreparedQuery<IUpsertSyncProtocolConfigSnapshotParams,IUpsertSyncProtocolConfigSnapshotResult>(upsertSyncProtocolConfigSnapshotIR);
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
/** 'GetSyncProtocolConfigSnapshot' parameters type */
|
|
327
|
+
export interface IGetSyncProtocolConfigSnapshotParams {
|
|
328
|
+
protocolName: string;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** 'GetSyncProtocolConfigSnapshot' return type */
|
|
332
|
+
export interface IGetSyncProtocolConfigSnapshotResult {
|
|
333
|
+
immutable_config: Json;
|
|
334
|
+
network_type: string;
|
|
335
|
+
protocol_name: string;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** 'GetSyncProtocolConfigSnapshot' query type */
|
|
339
|
+
export interface IGetSyncProtocolConfigSnapshotQuery {
|
|
340
|
+
params: IGetSyncProtocolConfigSnapshotParams;
|
|
341
|
+
result: IGetSyncProtocolConfigSnapshotResult;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const getSyncProtocolConfigSnapshotIR: any = {"usedParamSet":{"protocolName":true},"params":[{"name":"protocolName","required":true,"transform":{"type":"scalar"},"locs":[{"a":123,"b":136}]}],"statement":"SELECT protocol_name, network_type, immutable_config\nFROM effectstream.sync_protocol_config_snapshot\nWHERE protocol_name = :protocolName!"};
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Query generated from SQL:
|
|
348
|
+
* ```
|
|
349
|
+
* SELECT protocol_name, network_type, immutable_config
|
|
350
|
+
* FROM effectstream.sync_protocol_config_snapshot
|
|
351
|
+
* WHERE protocol_name = :protocolName!
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
export const getSyncProtocolConfigSnapshot = new PreparedQuery<IGetSyncProtocolConfigSnapshotParams,IGetSyncProtocolConfigSnapshotResult>(getSyncProtocolConfigSnapshotIR);
|
|
355
|
+
|
|
356
|
+
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/* @name getTableSchema */
|
|
2
|
+
SELECT
|
|
3
|
+
column_name, data_type, character_maximum_length, column_default, is_nullable
|
|
4
|
+
FROM
|
|
5
|
+
INFORMATION_SCHEMA.COLUMNS
|
|
6
|
+
WHERE
|
|
7
|
+
table_name = :tableName!
|
|
8
|
+
;
|
|
9
|
+
|
|
10
|
+
/* @name getLatestVersion */
|
|
11
|
+
SELECT
|
|
12
|
+
app_version_major, app_version_minor, app_version_patch, engine_version_major, engine_version_minor, engine_version_patch, block_height
|
|
13
|
+
FROM
|
|
14
|
+
effectstream.effectstream_version_history
|
|
15
|
+
ORDER BY block_height DESC
|
|
16
|
+
LIMIT 1
|
|
17
|
+
;
|
|
18
|
+
|
|
19
|
+
/* @name tableExists */
|
|
20
|
+
SELECT EXISTS (
|
|
21
|
+
SELECT FROM information_schema.tables
|
|
22
|
+
WHERE table_schema = 'effectstream'
|
|
23
|
+
AND table_name = 'effectstream_version_history'
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
/* @name insertPaimaEngineMigration */
|
|
27
|
+
INSERT INTO effectstream.effectstream_migration_history
|
|
28
|
+
(name, block_height, is_system_migration)
|
|
29
|
+
VALUES
|
|
30
|
+
(:name!, :blockHeight!, :isSystemMigration!)
|
|
31
|
+
;
|
|
32
|
+
|
|
33
|
+
/* @name insertPaimaEngineVersion */
|
|
34
|
+
INSERT INTO effectstream.effectstream_version_history
|
|
35
|
+
(app_version_major, app_version_minor, app_version_patch, engine_version_major, engine_version_minor, engine_version_patch, block_height)
|
|
36
|
+
VALUES
|
|
37
|
+
(:appVersionMajor!, :appVersionMinor!, :appVersionPatch!, :engineVersionMajor!, :engineVersionMinor!, :engineVersionPatch!, :blockHeight!)
|
|
38
|
+
;
|
|
39
|
+
|
|
40
|
+
/* @name findMigrationByName */
|
|
41
|
+
SELECT * FROM effectstream.effectstream_migration_history
|
|
42
|
+
WHERE name = :name!
|
|
43
|
+
AND is_system_migration = :isSystemMigration!
|
|
44
|
+
;
|
|
45
|
+
|
|
46
|
+
/* @name insertEngineExpectedVersion */
|
|
47
|
+
INSERT INTO effectstream.effectstream_expected_version
|
|
48
|
+
(app_version_major, app_version_minor, app_version_patch, engine_version_major, engine_version_minor, engine_version_patch, block_height)
|
|
49
|
+
VALUES
|
|
50
|
+
(:appVersionMajor!, :appVersionMinor!, :appVersionPatch!, :engineVersionMajor!, :engineVersionMinor!, :engineVersionPatch!, :blockHeight!)
|
|
51
|
+
;
|
|
52
|
+
|
|
53
|
+
/* @name getExpectedEngineVersion */
|
|
54
|
+
SELECT * FROM effectstream.effectstream_expected_version
|
|
55
|
+
ORDER BY block_height DESC
|
|
56
|
+
LIMIT 1
|
|
57
|
+
;
|
|
58
|
+
|
|
59
|
+
/* @name getAllTableNames */
|
|
60
|
+
SELECT tablename
|
|
61
|
+
FROM pg_tables
|
|
62
|
+
WHERE schemaname = 'public'
|
|
63
|
+
;
|
|
64
|
+
|
|
65
|
+
/* @name upsertSyncProtocolConfigSnapshot */
|
|
66
|
+
INSERT INTO effectstream.sync_protocol_config_snapshot (protocol_name, network_type, immutable_config)
|
|
67
|
+
VALUES (:protocolName!, :networkType!, :immutableConfig!)
|
|
68
|
+
ON CONFLICT (protocol_name) DO NOTHING
|
|
69
|
+
;
|
|
70
|
+
|
|
71
|
+
/* @name getSyncProtocolConfigSnapshot */
|
|
72
|
+
SELECT protocol_name, network_type, immutable_config
|
|
73
|
+
FROM effectstream.sync_protocol_config_snapshot
|
|
74
|
+
WHERE protocol_name = :protocolName!
|
|
75
|
+
;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Types generated for queries found in "src/sql/tables.sql" */
|
|
2
|
+
import { PreparedQuery } from '@pgtyped/runtime';
|
|
3
|
+
|
|
4
|
+
/** 'GetPrimaryKeyColumns' parameters type */
|
|
5
|
+
export interface IGetPrimaryKeyColumnsParams {
|
|
6
|
+
tableName?: string | null | void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** 'GetPrimaryKeyColumns' return type */
|
|
10
|
+
export interface IGetPrimaryKeyColumnsResult {
|
|
11
|
+
column_name: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** 'GetPrimaryKeyColumns' query type */
|
|
15
|
+
export interface IGetPrimaryKeyColumnsQuery {
|
|
16
|
+
params: IGetPrimaryKeyColumnsParams;
|
|
17
|
+
result: IGetPrimaryKeyColumnsResult;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const getPrimaryKeyColumnsIR: any = {"usedParamSet":{"tableName":true},"params":[{"name":"tableName","required":false,"transform":{"type":"scalar"},"locs":[{"a":175,"b":184}]}],"statement":"SELECT a.attname as \"column_name\"\nFROM pg_index i\nJOIN pg_attribute a ON a.attrelid = i.indrelid\n AND a.attnum = ANY(i.indkey)\nWHERE i.indrelid = CAST(:tableName AS TEXT)::regclass\nAND i.indisprimary"};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Query generated from SQL:
|
|
24
|
+
* ```
|
|
25
|
+
* SELECT a.attname as "column_name"
|
|
26
|
+
* FROM pg_index i
|
|
27
|
+
* JOIN pg_attribute a ON a.attrelid = i.indrelid
|
|
28
|
+
* AND a.attnum = ANY(i.indkey)
|
|
29
|
+
* WHERE i.indrelid = CAST(:tableName AS TEXT)::regclass
|
|
30
|
+
* AND i.indisprimary
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const getPrimaryKeyColumns = new PreparedQuery<IGetPrimaryKeyColumnsParams,IGetPrimaryKeyColumnsResult>(getPrimaryKeyColumnsIR);
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/** 'GetPublicTables' parameters type */
|
|
37
|
+
export type IGetPublicTablesParams = void;
|
|
38
|
+
|
|
39
|
+
/** 'GetPublicTables' return type */
|
|
40
|
+
export interface IGetPublicTablesResult {
|
|
41
|
+
table_name: string | null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 'GetPublicTables' query type */
|
|
45
|
+
export interface IGetPublicTablesQuery {
|
|
46
|
+
params: IGetPublicTablesParams;
|
|
47
|
+
result: IGetPublicTablesResult;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const getPublicTablesIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT table_name\nFROM information_schema.tables\nWHERE table_schema = 'public'"};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Query generated from SQL:
|
|
54
|
+
* ```
|
|
55
|
+
* SELECT table_name
|
|
56
|
+
* FROM information_schema.tables
|
|
57
|
+
* WHERE table_schema = 'public'
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export const getPublicTables = new PreparedQuery<IGetPublicTablesParams,IGetPublicTablesResult>(getPublicTablesIR);
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/** 'GetDynamicTables' parameters type */
|
|
64
|
+
export type IGetDynamicTablesParams = void;
|
|
65
|
+
|
|
66
|
+
/** 'GetDynamicTables' return type */
|
|
67
|
+
export interface IGetDynamicTablesResult {
|
|
68
|
+
table_name: string | null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 'GetDynamicTables' query type */
|
|
72
|
+
export interface IGetDynamicTablesQuery {
|
|
73
|
+
params: IGetDynamicTablesParams;
|
|
74
|
+
result: IGetDynamicTablesResult;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const getDynamicTablesIR: any = {"usedParamSet":{},"params":[],"statement":"SELECT table_name\nFROM information_schema.tables\nWHERE table_schema = 'primitives'"};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Query generated from SQL:
|
|
81
|
+
* ```
|
|
82
|
+
* SELECT table_name
|
|
83
|
+
* FROM information_schema.tables
|
|
84
|
+
* WHERE table_schema = 'primitives'
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export const getDynamicTables = new PreparedQuery<IGetDynamicTablesParams,IGetDynamicTablesResult>(getDynamicTablesIR);
|
|
88
|
+
|
|
89
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* @name getPrimaryKeyColumns */
|
|
2
|
+
SELECT a.attname as "column_name"
|
|
3
|
+
FROM pg_index i
|
|
4
|
+
JOIN pg_attribute a ON a.attrelid = i.indrelid
|
|
5
|
+
AND a.attnum = ANY(i.indkey)
|
|
6
|
+
WHERE i.indrelid = CAST(:tableName AS TEXT)::regclass
|
|
7
|
+
AND i.indisprimary;
|
|
8
|
+
|
|
9
|
+
/* @name getPublicTables */
|
|
10
|
+
SELECT table_name
|
|
11
|
+
FROM information_schema.tables
|
|
12
|
+
WHERE table_schema = 'public';
|
|
13
|
+
|
|
14
|
+
/* @name getDynamicTables */
|
|
15
|
+
SELECT table_name
|
|
16
|
+
FROM information_schema.tables
|
|
17
|
+
WHERE table_schema = 'primitives';
|
package/src/system.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { until } from "effection";
|
|
2
|
+
import type { Operation } from "effection";
|
|
3
|
+
import type { Pool, PoolClient } from "pg";
|
|
4
|
+
import {
|
|
5
|
+
getAllTableNames,
|
|
6
|
+
type IGetAllTableNamesResult,
|
|
7
|
+
} from "./sql/system.queries.ts";
|
|
8
|
+
|
|
9
|
+
type QueryablePool = Pool | PoolClient;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Truncates every table in the `public` schema and resets sequences.
|
|
13
|
+
*
|
|
14
|
+
* Intended for development flows only. The caller is responsible for holding any
|
|
15
|
+
* required database mutex before invoking this helper.
|
|
16
|
+
*
|
|
17
|
+
* @param dbConn - Active pool or client to run queries against.
|
|
18
|
+
*/
|
|
19
|
+
export function* resetPublicTables(
|
|
20
|
+
dbConn: QueryablePool,
|
|
21
|
+
): Operation<void> {
|
|
22
|
+
const tableRows = (yield* until(
|
|
23
|
+
getAllTableNames.run(undefined, dbConn),
|
|
24
|
+
)) as IGetAllTableNamesResult[];
|
|
25
|
+
|
|
26
|
+
const tableNames = tableRows
|
|
27
|
+
.map((row) => row.tablename)
|
|
28
|
+
.filter((name): name is string => Boolean(name));
|
|
29
|
+
|
|
30
|
+
if (tableNames.length === 0) {
|
|
31
|
+
console.log("[DEV RESET] No public tables found to truncate.");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const qualified = tableNames.map((name) => `"public"."${name}"`).join(", ");
|
|
36
|
+
console.log(`[DEV RESET] Truncating public tables: ${qualified}`);
|
|
37
|
+
|
|
38
|
+
yield* until(
|
|
39
|
+
dbConn.query(`TRUNCATE TABLE ${qualified} RESTART IDENTITY CASCADE`),
|
|
40
|
+
);
|
|
41
|
+
}
|