envio 2.25.1 → 2.25.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/PgStorage.res +19 -4
- package/src/PgStorage.res.js +6 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "envio",
|
|
3
|
-
"version": "v2.25.
|
|
3
|
+
"version": "v2.25.2",
|
|
4
4
|
"description": "A latency and sync speed optimized, developer friendly blockchain data indexer.",
|
|
5
5
|
"bin": "./bin.js",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://envio.dev",
|
|
27
27
|
"optionalDependencies": {
|
|
28
|
-
"envio-linux-x64": "v2.25.
|
|
29
|
-
"envio-linux-arm64": "v2.25.
|
|
30
|
-
"envio-darwin-x64": "v2.25.
|
|
31
|
-
"envio-darwin-arm64": "v2.25.
|
|
28
|
+
"envio-linux-x64": "v2.25.2",
|
|
29
|
+
"envio-linux-arm64": "v2.25.2",
|
|
30
|
+
"envio-darwin-x64": "v2.25.2",
|
|
31
|
+
"envio-darwin-arm64": "v2.25.2"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@envio-dev/hypersync-client": "0.6.5",
|
package/src/PgStorage.res
CHANGED
|
@@ -58,6 +58,7 @@ let makeInitializeTransaction = (
|
|
|
58
58
|
~generalTables=[],
|
|
59
59
|
~entities=[],
|
|
60
60
|
~enums=[],
|
|
61
|
+
~reuseExistingPgSchema=false,
|
|
61
62
|
) => {
|
|
62
63
|
let allTables = generalTables->Array.copy
|
|
63
64
|
let allEntityTables = []
|
|
@@ -69,9 +70,16 @@ let makeInitializeTransaction = (
|
|
|
69
70
|
let derivedSchema = Schema.make(allEntityTables)
|
|
70
71
|
|
|
71
72
|
let query = ref(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
(
|
|
74
|
+
reuseExistingPgSchema
|
|
75
|
+
// Hosted Service already have a DB with the created public schema
|
|
76
|
+
// It also doesn't allow to simply drop it,
|
|
77
|
+
// so we reuse an existing schema when it's empty (our case)
|
|
78
|
+
? ""
|
|
79
|
+
: `DROP SCHEMA IF EXISTS "${pgSchema}" CASCADE;
|
|
80
|
+
CREATE SCHEMA "${pgSchema}";\n`
|
|
81
|
+
) ++
|
|
82
|
+
`GRANT ALL ON SCHEMA "${pgSchema}" TO "${pgUser}";
|
|
75
83
|
GRANT ALL ON SCHEMA "${pgSchema}" TO public;`,
|
|
76
84
|
)
|
|
77
85
|
|
|
@@ -439,7 +447,14 @@ let make = (~sql: Postgres.sql, ~pgSchema, ~pgUser): Persistence.storage => {
|
|
|
439
447
|
)
|
|
440
448
|
}
|
|
441
449
|
|
|
442
|
-
let queries = makeInitializeTransaction(
|
|
450
|
+
let queries = makeInitializeTransaction(
|
|
451
|
+
~pgSchema,
|
|
452
|
+
~pgUser,
|
|
453
|
+
~generalTables,
|
|
454
|
+
~entities,
|
|
455
|
+
~enums,
|
|
456
|
+
~reuseExistingPgSchema=schemaTableNames->Utils.Array.isEmpty,
|
|
457
|
+
)
|
|
443
458
|
// Execute all queries within a single transaction for integrity
|
|
444
459
|
let _ = await sql->Postgres.beginSql(sql => {
|
|
445
460
|
queries->Js.Array2.map(query => sql->Postgres.unsafe(query))
|
package/src/PgStorage.res.js
CHANGED
|
@@ -59,10 +59,11 @@ function makeCreateTableQuery(table, pgSchema) {
|
|
|
59
59
|
) + ");";
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
function makeInitializeTransaction(pgSchema, pgUser, generalTablesOpt, entitiesOpt, enumsOpt) {
|
|
62
|
+
function makeInitializeTransaction(pgSchema, pgUser, generalTablesOpt, entitiesOpt, enumsOpt, reuseExistingPgSchemaOpt) {
|
|
63
63
|
var generalTables = generalTablesOpt !== undefined ? generalTablesOpt : [];
|
|
64
64
|
var entities = entitiesOpt !== undefined ? entitiesOpt : [];
|
|
65
65
|
var enums = enumsOpt !== undefined ? enumsOpt : [];
|
|
66
|
+
var reuseExistingPgSchema = reuseExistingPgSchemaOpt !== undefined ? reuseExistingPgSchemaOpt : false;
|
|
66
67
|
var allTables = $$Array.copy(generalTables);
|
|
67
68
|
var allEntityTables = [];
|
|
68
69
|
entities.forEach(function (entity) {
|
|
@@ -72,7 +73,9 @@ function makeInitializeTransaction(pgSchema, pgUser, generalTablesOpt, entitiesO
|
|
|
72
73
|
});
|
|
73
74
|
var derivedSchema = Schema.make(allEntityTables);
|
|
74
75
|
var query = {
|
|
75
|
-
contents:
|
|
76
|
+
contents: (
|
|
77
|
+
reuseExistingPgSchema ? "" : "DROP SCHEMA IF EXISTS \"" + pgSchema + "\" CASCADE;\nCREATE SCHEMA \"" + pgSchema + "\";\n"
|
|
78
|
+
) + ("GRANT ALL ON SCHEMA \"" + pgSchema + "\" TO \"" + pgUser + "\";\nGRANT ALL ON SCHEMA \"" + pgSchema + "\" TO public;")
|
|
76
79
|
};
|
|
77
80
|
enums.forEach(function (enumConfig) {
|
|
78
81
|
var enumCreateQuery = "CREATE TYPE \"" + pgSchema + "\"." + enumConfig.name + " AS ENUM(" + enumConfig.variants.map(function (v) {
|
|
@@ -300,7 +303,7 @@ function make(sql, pgSchema, pgUser) {
|
|
|
300
303
|
})) {
|
|
301
304
|
Js_exn.raiseError("Cannot run Envio migrations on PostgreSQL schema \"" + pgSchema + "\" because it contains non-Envio tables. Running migrations would delete all data in this schema.\n\nTo resolve this:\n1. If you want to use this schema, first backup any important data, then drop it with: \"pnpm envio local db-migrate down\"\n2. Or specify a different schema name by setting the \"ENVIO_PG_PUBLIC_SCHEMA\" environment variable\n3. Or manually drop the schema in your database if you're certain the data is not needed.");
|
|
302
305
|
}
|
|
303
|
-
var queries = makeInitializeTransaction(pgSchema, pgUser, generalTables, entities, enums);
|
|
306
|
+
var queries = makeInitializeTransaction(pgSchema, pgUser, generalTables, entities, enums, Utils.$$Array.isEmpty(schemaTableNames));
|
|
304
307
|
await sql.begin(function (sql) {
|
|
305
308
|
return queries.map(function (query) {
|
|
306
309
|
return sql.unsafe(query);
|