Skip to content

Commit

Permalink
Update setup scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
trizin authored Jun 23, 2023
1 parent 2fc1f6e commit a64bc82
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 68 deletions.
33 changes: 6 additions & 27 deletions init_tables.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
// bump start script
require("dotenv").config()
const mysql = require("mysql2")
const {
allocationsTable,
nftVolsTable,
vebalsTable,
rewardsInfo,
nftinfoTable
} = require("./db/structure")
const dbStructure = require("./db/structure");

const con = mysql.createConnection({
host: process.env["MYSQL_HOST"],
Expand All @@ -18,25 +12,10 @@ const con = mysql.createConnection({

con.connect(function (err) {
if (err) throw err

con.query(allocationsTable, function (err, result) {
if (err) throw err
console.log("Table allocations created")
})
con.query(nftVolsTable, function (err, result) {
if (err) throw err
console.log("Table nft_vols created")
})
con.query(vebalsTable, function (err, result) {
if (err) throw err
console.log("Table vebals created")
})
con.query(rewardsInfo, function (err, result) {
if (err) throw err
console.log("Table rewards_info created")
})
con.query(nftinfoTable, function (err, result) {
if (err) throw err
console.log("Table nft_info created")
Object.entries(dbStructure).forEach(([tableName, sqlQuery]) => {
con.query(sqlQuery, function (err, result) {
if (err) throw err
console.log(`Table ${tableName} created`)
})
})
})
48 changes: 7 additions & 41 deletions src/db/setup.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,14 @@
require("dotenv").config()
const mysql = require("mysql2")
const {
allocationsTable,
nftVolsTable,
vebalsTable,
rewardsInfo,
passiveRewardsInfo,
nftinfoTable,
rewardsSummary,
ownersInfo
} = require("../../db/structure")
const dbStructure = require("./db/structure");


function createTables(con) {
con.query(allocationsTable, function (err, result) {
if (err) throw err
console.log("Table allocations created")
})
con.query(nftVolsTable, function (err, result) {
if (err) throw err
console.log("Table nft_vols created")
})
con.query(vebalsTable, function (err, result) {
if (err) throw err
console.log("Table vebals created")
})
con.query(rewardsInfo, function (err, result) {
if (err) throw err
console.log("Table rewards_info created")
})
con.query(passiveRewardsInfo, function (err, result) {
if (err) throw err
console.log("Table passive_rewards_info created")
})
con.query(nftinfoTable, function (err, result) {
if (err) throw err
console.log("Table nft_info created")
})
con.query(rewardsSummary, function (err, result) {
if (err) throw err
console.log("Table rewards_summary created")
})
con.query(ownersInfo, function (err, result) {
if (err) throw err
console.log("Table owners_info created")
Object.entries(dbStructure).forEach(([tableName, sqlQuery]) => {
con.query(sqlQuery, function (err, result) {
if (err) throw err
console.log(`Table ${tableName} created`)
})
})
}

Expand Down

0 comments on commit a64bc82

Please sign in to comment.