envio 2.22.1 → 2.22.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envio",
3
- "version": "v2.22.1",
3
+ "version": "v2.22.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.22.1",
29
- "envio-linux-arm64": "v2.22.1",
30
- "envio-darwin-x64": "v2.22.1",
31
- "envio-darwin-arm64": "v2.22.1"
28
+ "envio-linux-x64": "v2.22.2",
29
+ "envio-linux-arm64": "v2.22.2",
30
+ "envio-darwin-x64": "v2.22.2",
31
+ "envio-darwin-arm64": "v2.22.2"
32
32
  },
33
33
  "dependencies": {
34
34
  "@envio-dev/hypersync-client": "0.6.5",
package/src/PgStorage.res CHANGED
@@ -52,7 +52,14 @@ let makeCreateTableSqlUnsafe = (table: Table.table, ~pgSchema) => {
52
52
  : ""});`
53
53
  }
54
54
 
55
- let makeInitializeTransaction = (~pgSchema, ~staticTables, ~entities, ~enums, ~cleanRun) => {
55
+ let makeInitializeTransaction = (
56
+ ~pgSchema,
57
+ ~pgUser,
58
+ ~staticTables,
59
+ ~entities,
60
+ ~enums,
61
+ ~cleanRun,
62
+ ) => {
56
63
  let allTables = staticTables->Array.copy
57
64
  let allEntityTables = []
58
65
  entities->Js.Array2.forEach((entity: Internal.entityConfig) => {
@@ -69,7 +76,7 @@ let makeInitializeTransaction = (~pgSchema, ~staticTables, ~entities, ~enums, ~c
69
76
  CREATE SCHEMA "${pgSchema}";`
70
77
  : `CREATE SCHEMA IF NOT EXISTS "${pgSchema}";`
71
78
  ) ++
72
- `GRANT ALL ON SCHEMA "${pgSchema}" TO postgres;
79
+ `GRANT ALL ON SCHEMA "${pgSchema}" TO ${pgUser};
73
80
  GRANT ALL ON SCHEMA "${pgSchema}" TO public;`,
74
81
  )
75
82
 
@@ -141,7 +148,7 @@ END IF;`
141
148
  ]->Js.Array2.concat(functionsQuery.contents !== "" ? [functionsQuery.contents] : [])
142
149
  }
143
150
 
144
- let make = (~sql: Postgres.sql, ~pgSchema): Persistence.storage => {
151
+ let make = (~sql: Postgres.sql, ~pgSchema, ~pgUser): Persistence.storage => {
145
152
  let isInitialized = async () => {
146
153
  let schemas =
147
154
  await sql->Postgres.unsafe(
@@ -151,7 +158,14 @@ let make = (~sql: Postgres.sql, ~pgSchema): Persistence.storage => {
151
158
  }
152
159
 
153
160
  let initialize = async (~entities, ~staticTables, ~enums, ~cleanRun) => {
154
- let queries = makeInitializeTransaction(~pgSchema, ~staticTables, ~entities, ~enums, ~cleanRun)
161
+ let queries = makeInitializeTransaction(
162
+ ~pgSchema,
163
+ ~pgUser,
164
+ ~staticTables,
165
+ ~entities,
166
+ ~enums,
167
+ ~cleanRun,
168
+ )
155
169
  // Execute all queries within a single transaction for integrity
156
170
  let _ = await sql->Postgres.beginSql(sql => {
157
171
  queries->Js.Array2.map(query => sql->Postgres.unsafe(query))
@@ -52,7 +52,7 @@ function makeCreateTableSqlUnsafe(table, pgSchema) {
52
52
  ) + ");";
53
53
  }
54
54
 
55
- function makeInitializeTransaction(pgSchema, staticTables, entities, enums, cleanRun) {
55
+ function makeInitializeTransaction(pgSchema, pgUser, staticTables, entities, enums, cleanRun) {
56
56
  var allTables = $$Array.copy(staticTables);
57
57
  var allEntityTables = [];
58
58
  entities.forEach(function (entity) {
@@ -64,7 +64,7 @@ function makeInitializeTransaction(pgSchema, staticTables, entities, enums, clea
64
64
  var query = {
65
65
  contents: (
66
66
  cleanRun ? "DROP SCHEMA IF EXISTS \"" + pgSchema + "\" CASCADE;\nCREATE SCHEMA \"" + pgSchema + "\";" : "CREATE SCHEMA IF NOT EXISTS \"" + pgSchema + "\";"
67
- ) + ("GRANT ALL ON SCHEMA \"" + pgSchema + "\" TO postgres;\nGRANT ALL ON SCHEMA \"" + pgSchema + "\" TO public;")
67
+ ) + ("GRANT ALL ON SCHEMA \"" + pgSchema + "\" TO " + pgUser + ";\nGRANT ALL ON SCHEMA \"" + pgSchema + "\" TO public;")
68
68
  };
69
69
  enums.forEach(function (enumConfig) {
70
70
  var enumCreateQuery = "CREATE TYPE \"" + pgSchema + "\"." + enumConfig.name + " AS ENUM(" + enumConfig.variants.map(function (v) {
@@ -98,13 +98,13 @@ function makeInitializeTransaction(pgSchema, staticTables, entities, enums, clea
98
98
  return [cleanRun ? query.contents : "DO $$ BEGIN " + query.contents + " END $$;"].concat(functionsQuery.contents !== "" ? [functionsQuery.contents] : []);
99
99
  }
100
100
 
101
- function make(sql, pgSchema) {
101
+ function make(sql, pgSchema, pgUser) {
102
102
  var isInitialized = async function () {
103
103
  var schemas = await sql.unsafe("SELECT schema_name FROM information_schema.schemata WHERE schema_name = '" + pgSchema + "';");
104
104
  return Utils.$$Array.notEmpty(schemas);
105
105
  };
106
106
  var initialize = async function (entities, staticTables, enums, cleanRun) {
107
- var queries = makeInitializeTransaction(pgSchema, staticTables, entities, enums, cleanRun);
107
+ var queries = makeInitializeTransaction(pgSchema, pgUser, staticTables, entities, enums, cleanRun);
108
108
  await sql.begin(function (sql) {
109
109
  return queries.map(function (query) {
110
110
  return sql.unsafe(query);