-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from makerdao/insert-script
try adding script to insert authorized creators
- Loading branch information
Showing
7 changed files
with
63 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
query pollCreators { | ||
pollCreators { | ||
nodes { | ||
address | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters