diff --git a/.github/workflows/aws-prod.yml b/.github/workflows/aws-prod.yml index 0a9a105..48a7d90 100644 --- a/.github/workflows/aws-prod.yml +++ b/.github/workflows/aws-prod.yml @@ -18,10 +18,10 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v1-node16 with: aws-access-key-id: ${{ secrets.POLLINGDB2_PROD_AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.POLLINGDB2_PROD_AWS_SECRET_ACCESS_KEY }} diff --git a/.github/workflows/aws-staging.yml b/.github/workflows/aws-staging.yml index dc6fd8b..96990d3 100644 --- a/.github/workflows/aws-staging.yml +++ b/.github/workflows/aws-staging.yml @@ -21,10 +21,10 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v1-node16 with: aws-access-key-id: ${{ secrets.POLLINGDB2_STAGING_AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.POLLINGDB2_STAGING_AWS_SECRET_ACCESS_KEY }} diff --git a/insert_poll_creators.js b/insert_poll_creators.js new file mode 100644 index 0000000..4398171 --- /dev/null +++ b/insert_poll_creators.js @@ -0,0 +1,34 @@ +require('dotenv').config(); + +const pgp = require('pg-promise')(); + +const db = pgp({ + host: process.env.VL_DB_HOST, + port: process.env.VL_DB_PORT, + database: process.env.VL_DB_DATABASE, + user: process.env.VL_DB_USER, + password: process.env.VL_DB_PASSWORD +}); + +const authorizedCreatorsArray = (process.env.AUTHORIZED_CREATORS || '').split(',').map(creator => creator.toLowerCase()); + +const deleteQuery = 'DELETE FROM polling.creators'; +const insertQuery = 'INSERT INTO polling.creators (address) VALUES ($1)'; + +async function executeQueries() { + try { + await db.none(deleteQuery); + console.log('All previous creators deleted.'); + + for (const creator of authorizedCreatorsArray) { + await db.none(insertQuery, creator); + console.log(`Creator ${creator} added successfully.`); + } + + console.log('All authorized creators added successfully.'); + } catch (err) { + console.error('Error: ', err); + } +} + +executeQueries().catch(err => console.error('Error: ', err)); \ No newline at end of file diff --git a/migrations/072-poll-creators.sql b/migrations/072-poll-creators.sql new file mode 100644 index 0000000..e226f99 --- /dev/null +++ b/migrations/072-poll-creators.sql @@ -0,0 +1,9 @@ +create table polling.creators ( + address character varying(66) not null +); + +create or replace function api.poll_creators() +returns setof polling.creators as $$ + select * + from polling.creators; +$$ language sql stable strict; diff --git a/package.json b/package.json index d85356a..2d9b7b3 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,13 @@ "scripts": { "start-etl": "node -r ./loadenv.js ./node_modules/@makerdao-dux/spock-etl/dist/bin/etl ./config.js", "start-sync": "yarn migrate", - "migrate": "node -r ./loadenv.js ./node_modules/@makerdao-dux/spock-etl/dist/bin/migrate ./config.js", + "migrate:only": "node -r ./loadenv.js ./node_modules/@makerdao-dux/spock-etl/dist/bin/migrate ./config.js", + "migrate": "yarn migrate:only && yarn insert-poll-creators", "start-api": "node -r ./loadenv.js ./node_modules/@makerdao-dux/spock-graphql-api/dist/index.js ./config.js", "test": "jest", "test:ci": "./tests/run-tests.sh", - "repl": "node --experimental-repl-await -r ./loadenv.js ./repl" + "repl": "node --experimental-repl-await -r ./loadenv.js ./repl", + "insert-poll-creators": "node insert_poll_creators.js" }, "dependencies": { "@makerdao-dux/spock-etl": "^0.2.0", @@ -20,13 +22,13 @@ "bignumber.js": "^9.0.2", "consola": "^2.15.3", "dotenv-flow": "^2.0.0", - "ethers": "krzkaczor/ethers.js#kk/get-logs-multiple-address-build" + "ethers": "krzkaczor/ethers.js#kk/get-logs-multiple-address-build", + "pg-promise": "10.11.1" }, "devDependencies": { "eslint": "^8.23.1", "eslint-plugin-prettier": "^4.2.1", "graphql-request": "^1.8.2", - "jest": "^24.8.0", - "pg-promise": "^8.7.2" + "jest": "^24.8.0" } } diff --git a/queries/pollCreators.graphql b/queries/pollCreators.graphql new file mode 100644 index 0000000..66b719f --- /dev/null +++ b/queries/pollCreators.graphql @@ -0,0 +1,7 @@ +query pollCreators { + pollCreators { + nodes { + address + } + } +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 0b1b574..61e5d70 100644 --- a/yarn.lock +++ b/yarn.lock @@ -938,11 +938,6 @@ asn1@~0.2.3: dependencies: safer-buffer "~2.1.0" -assert-options@0.1.3: - version "0.1.3" - resolved "https://registry.yarnpkg.com/assert-options/-/assert-options-0.1.3.tgz#ea56c6a67a558eefb9db52c394f2fa92b94bfcde" - integrity sha512-DXrZ5WkCv/igD+H8OmeUTl9k0pBhYSTdyA7DRZoSJERCzQ8Z2v85yDjkhYVnHUOeCXGfCNKaogRbLWQsIQbtpg== - assert-options@0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/assert-options/-/assert-options-0.7.0.tgz#82c27618d9c0baa5e9da8ef607ee261a44ed6e5e" @@ -3704,11 +3699,6 @@ makeerror@1.0.12: dependencies: tmpl "1.0.5" -manakin@0.5.2: - version "0.5.2" - resolved "https://registry.yarnpkg.com/manakin/-/manakin-0.5.2.tgz#abe3df430ca6085f6983f6e4cf5af0298f4d30cc" - integrity sha512-pfDSB7QYoVg0Io4KMV9hhPoXpj6p0uBscgtyUSKCOFZe8bqgbpStfgnKIbF/ulnr6U3ICu4OqdyxAqBgOhZwBQ== - map-cache@^0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf" @@ -4232,11 +4222,6 @@ pg-int8@1.0.1: resolved "https://registry.yarnpkg.com/pg-int8/-/pg-int8-1.0.1.tgz#943bd463bf5b71b4170115f80f8efc9a0c0eb78c" integrity sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw== -pg-minify@1.4.1: - version "1.4.1" - resolved "https://registry.yarnpkg.com/pg-minify/-/pg-minify-1.4.1.tgz#ff9a9febefa6cec53055e2fd24e3115a275e2a08" - integrity sha512-8aZ9xdx7Pe/ppFYVOqvU5KgmM6ttXjaBlsl9Y8yzrUH4xSNVucJKKOwm4Y4H+LCvzZGjZIm4Rkf2Ajt5ixtkBQ== - pg-minify@1.6.2: version "1.6.2" resolved "https://registry.yarnpkg.com/pg-minify/-/pg-minify-1.6.2.tgz#055acfe862cfca3ca0a529020846b0f308d68e70" @@ -4247,7 +4232,7 @@ pg-packet-stream@^1.1.0: resolved "https://registry.yarnpkg.com/pg-packet-stream/-/pg-packet-stream-1.1.0.tgz#e45c3ae678b901a2873af1e17b92d787962ef914" integrity sha512-kRBH0tDIW/8lfnnOyTwKD23ygJ/kexQVXZs7gEyBljw4FYqimZFxnMMx50ndZ8In77QgfGuItS5LLclC2TtjYg== -pg-pool@^2.0.10, pg-pool@^2.0.4: +pg-pool@^2.0.10: version "2.0.10" resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-2.0.10.tgz#842ee23b04e86824ce9d786430f8365082d81c4a" integrity sha512-qdwzY92bHf3nwzIUcj+zJ0Qo5lpG/YxchahxIN8+ZVmXqkahKXsnl2aiJPHLYN9o5mB/leG+Xh6XKxtP7e0sjg== @@ -4257,7 +4242,7 @@ pg-pool@^3.4.1, pg-pool@^3.5.1: resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-3.5.1.tgz#f499ce76f9bf5097488b3b83b19861f28e4ed905" integrity sha512-6iCR0wVrro6OOHFsyavV+i6KYL4lVNyYAB9RD18w66xSzN+d8b66HiwuP30Gp1SH5O9T82fckkzsRjlrhD0ioQ== -pg-promise@^10.4.4: +pg-promise@10.11.1, pg-promise@^10.4.4: version "10.11.1" resolved "https://registry.yarnpkg.com/pg-promise/-/pg-promise-10.11.1.tgz#62348927da636aa74d2c20510cfbd12e85f104ae" integrity sha512-HAv32WSKf2m2RqHerW5RmANn/mcXIwWXbg/gOfGQcoS0SE+8iBi3Jj4JmoR4PNzSEozo/y/npy4e6F16psOItw== @@ -4267,17 +4252,6 @@ pg-promise@^10.4.4: pg-minify "1.6.2" spex "3.2.0" -pg-promise@^8.7.2: - version "8.7.5" - resolved "https://registry.yarnpkg.com/pg-promise/-/pg-promise-8.7.5.tgz#d66beb86b041ae6e9dc66c4b5c7fb04dafcd18bb" - integrity sha512-r/OmS1b1i0nA0KHqlbcAoMLoNo3EGUdcZxaseyXnHrzepcS8ciK516Lw6/lIb6AeWI85ZOBSNdiPlw22xoFx3A== - dependencies: - assert-options "0.1.3" - manakin "0.5.2" - pg "7.11.0" - pg-minify "1.4.1" - spex "2.2.0" - pg-protocol@*, pg-protocol@^1.5.0: version "1.5.0" resolved "https://registry.yarnpkg.com/pg-protocol/-/pg-protocol-1.5.0.tgz#b5dd452257314565e2d54ab3c132adc46565a6a0" @@ -4304,30 +4278,6 @@ pg-types@^2.1.0, pg-types@^2.2.0: postgres-date "~1.0.4" postgres-interval "^1.1.0" -pg-types@~2.0.0: - version "2.0.1" - resolved "https://registry.yarnpkg.com/pg-types/-/pg-types-2.0.1.tgz#b8585a37f2a9c7b386747e44574799549e5f4933" - integrity sha512-b7y6QM1VF5nOeX9ukMQ0h8a9z89mojrBHXfJeSug4mhL0YpxNBm83ot2TROyoAmX/ZOX3UbwVO4EbH7i1ZZNiw== - dependencies: - pg-int8 "1.0.1" - postgres-array "~2.0.0" - postgres-bytea "~1.0.0" - postgres-date "~1.0.4" - postgres-interval "^1.1.0" - -pg@7.11.0: - version "7.11.0" - resolved "https://registry.yarnpkg.com/pg/-/pg-7.11.0.tgz#a8b9ae9cf19199b7952b72957573d0a9c5e67c0c" - integrity sha512-YO4V7vCmEMGoF390LJaFaohWNKaA2ayoQOEZmiHVcAUF+YsRThpf/TaKCgSvsSE7cDm37Q/Cy3Gz41xiX/XjTw== - dependencies: - buffer-writer "2.0.0" - packet-reader "1.0.0" - pg-connection-string "0.1.3" - pg-pool "^2.0.4" - pg-types "~2.0.0" - pgpass "1.x" - semver "4.3.2" - pg@8.7.1: version "8.7.1" resolved "https://registry.yarnpkg.com/pg/-/pg-8.7.1.tgz#9ea9d1ec225980c36f94e181d009ab9f4ce4c471" @@ -5120,11 +5070,6 @@ spdx-license-ids@^3.0.0: resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.11.tgz#50c0d8c40a14ec1bf449bae69a0ea4685a9d9f95" integrity sha512-Ctl2BrFiM0X3MANYgj3CkygxhRmr9mi6xhejbdO960nF6EDJApTYpn0BQnDKlnNBULKiCN1n3w9EBkHK8ZWg+g== -spex@2.2.0: - version "2.2.0" - resolved "https://registry.yarnpkg.com/spex/-/spex-2.2.0.tgz#b0d825f43ca3c88a35bda79553296c83c07b4d63" - integrity sha512-iwBxqKe4ZKD+P/i/WdzWw5qxmerHvzVb29wQm4zwYaDPuwsTKjS7nbqt8OyBSLAi2q0ZFUN3F2b4erX0UwF0fA== - spex@3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/spex/-/spex-3.2.0.tgz#fa4a21922407e112624977b445a6d634578a1127"