Switch to postgres in docker compose
This commit is contained in:
parent
5d2e2b5274
commit
9f300f763a
4 changed files with 35 additions and 23 deletions
|
@ -9,13 +9,13 @@ NODE_ENV=development
|
||||||
TOKEN=
|
TOKEN=
|
||||||
|
|
||||||
# Put database type here (mongo or postgres)
|
# Put database type here (mongo or postgres)
|
||||||
DB_DRIVER=mongo
|
DB_DRIVER=postgres
|
||||||
|
|
||||||
# Put the database connection URL here
|
# Put the database connection URL here
|
||||||
# Example for PostgreSQL:
|
|
||||||
# DB=postgresql://esmbot@localhost:5432/esmbot
|
|
||||||
# Example for MongoDB:
|
# Example for MongoDB:
|
||||||
DB=mongodb://localhost:27017/esmBot
|
# DB=mongodb://localhost:27017/esmBot
|
||||||
|
# Example for PostgreSQL:
|
||||||
|
DB=postgresql://esmbot:verycoolpass100@localhost:5432/esmbot
|
||||||
|
|
||||||
# Put snowflake ID of bot owner here
|
# Put snowflake ID of bot owner here
|
||||||
OWNER=
|
OWNER=
|
||||||
|
|
|
@ -25,7 +25,7 @@ services:
|
||||||
- api
|
- api
|
||||||
- chrome
|
- chrome
|
||||||
- lavalink
|
- lavalink
|
||||||
- mongo
|
- postgres
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
esmbot:
|
esmbot:
|
||||||
|
@ -64,23 +64,28 @@ services:
|
||||||
esmbot:
|
esmbot:
|
||||||
ipv4_address: 172.20.0.5
|
ipv4_address: 172.20.0.5
|
||||||
|
|
||||||
mongo:
|
postgres:
|
||||||
container_name: mongo
|
container_name: postgres
|
||||||
image: mongo:latest
|
image: postgres:13-alpine
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
volumes:
|
volumes:
|
||||||
- mongo-data:/data/db
|
- pg-data:/var/lib/postgresql/data
|
||||||
|
- ./utils/psqlinit.sh:/docker-entrypoint-initdb.d/psqlinit.sh
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: verycoolpass100
|
||||||
|
POSTGRES_USER: esmbot
|
||||||
|
POSTGRES_DB: esmbot
|
||||||
networks:
|
networks:
|
||||||
esmbot:
|
esmbot:
|
||||||
ipv4_address: 172.20.0.6
|
ipv4_address: 172.20.0.6
|
||||||
|
|
||||||
mongo-express:
|
adminer:
|
||||||
image: mongo-express
|
image: adminer
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
depends_on:
|
depends_on:
|
||||||
- mongo
|
- postgres
|
||||||
ports:
|
ports:
|
||||||
- 8888:8081
|
- 8888:8080
|
||||||
networks:
|
networks:
|
||||||
esmbot:
|
esmbot:
|
||||||
ipv4_address: 172.20.0.7
|
ipv4_address: 172.20.0.7
|
||||||
|
@ -88,7 +93,8 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
bot-help:
|
bot-help:
|
||||||
bot-temp:
|
bot-temp:
|
||||||
mongo-data:
|
#mongo-data:
|
||||||
|
pg-data:
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
esmbot:
|
esmbot:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require("dotenv").config();
|
//require("dotenv").config();
|
||||||
const { Pool } = require("pg");
|
const { Pool } = require("pg");
|
||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
connectionString: process.env.DB
|
connectionString: process.env.DB
|
||||||
|
@ -24,15 +24,14 @@ const Global = mongoose.model("Global", globalSchema);
|
||||||
const guilds = await Guild.find();
|
const guilds = await Guild.find();
|
||||||
try {
|
try {
|
||||||
await pool.query("CREATE TABLE guilds ( guild_id VARCHAR(30) NOT NULL, tags json NOT NULL, prefix VARCHAR(15) NOT NULL, warns json NOT NULL, disabled text ARRAY NOT NULL, tags_disabled boolean NOT NULL )");
|
await pool.query("CREATE TABLE guilds ( guild_id VARCHAR(30) NOT NULL, tags json NOT NULL, prefix VARCHAR(15) NOT NULL, warns json NOT NULL, disabled text ARRAY NOT NULL, tags_disabled boolean NOT NULL )");
|
||||||
} catch {
|
} catch (e) {
|
||||||
console.log("Skipping table creation due to error...");
|
console.error(`Skipping table creation due to error: ${e}`);
|
||||||
}
|
}
|
||||||
for (const guild of guilds) {
|
for (const guild of guilds) {
|
||||||
console.log(guild.tagsDisabled);
|
|
||||||
if ((await pool.query("SELECT * FROM guilds WHERE guild_id = $1", [guild.id])).rows.length !== 0) {
|
if ((await pool.query("SELECT * FROM guilds WHERE guild_id = $1", [guild.id])).rows.length !== 0) {
|
||||||
await pool.query("UPDATE guilds SET tags = $1, prefix = $2, warns = $3, disabled = $4, tags_disabled = $5 WHERE guild_id = $6", [guild.tags, guild.prefix.substring(0, 15), {}, guild.disabled ? guild.disabled : guild.disabledChannels, guild.tagsDisabled === undefined ? false : guild.tagsDisabled, guild.id]);
|
await pool.query("UPDATE guilds SET tags = $1, prefix = $2, disabled = $3, tags_disabled = $4 WHERE guild_id = $5", [guild.tags, guild.prefix.substring(0, 15), guild.disabled ? guild.disabled : guild.disabledChannels, guild.tagsDisabled === undefined ? false : guild.tagsDisabled, guild.id]);
|
||||||
} else {
|
} else {
|
||||||
await pool.query("INSERT INTO guilds (guild_id, tags, prefix, warns, disabled, tags_disabled) VALUES ($1, $2, $3, $4, $5, $6)", [guild.id, guild.tags, guild.prefix.substring(0, 15), {}, guild.disabled ? guild.disabled : guild.disabledChannels, guild.tagsDisabled === undefined ? false : guild.tagsDisabled]);
|
await pool.query("INSERT INTO guilds (guild_id, tags, prefix, disabled, tags_disabled) VALUES ($1, $2, $3, $4, $5)", [guild.id, guild.tags, guild.prefix.substring(0, 15), guild.disabled ? guild.disabled : guild.disabledChannels, guild.tagsDisabled === undefined ? false : guild.tagsDisabled]);
|
||||||
}
|
}
|
||||||
console.log(`Migrated guild with ID ${guild.id}`);
|
console.log(`Migrated guild with ID ${guild.id}`);
|
||||||
}
|
}
|
||||||
|
@ -40,8 +39,8 @@ const Global = mongoose.model("Global", globalSchema);
|
||||||
const global = await Global.findOne();
|
const global = await Global.findOne();
|
||||||
try {
|
try {
|
||||||
await pool.query("CREATE TABLE counts ( command VARCHAR NOT NULL, count integer NOT NULL )");
|
await pool.query("CREATE TABLE counts ( command VARCHAR NOT NULL, count integer NOT NULL )");
|
||||||
} catch {
|
} catch (e) {
|
||||||
console.log("Skipping table creation due to error...");
|
console.error(`Skipping table creation due to error: ${e}`);
|
||||||
}
|
}
|
||||||
console.log(global);
|
console.log(global);
|
||||||
for (const [key, value] of global.cmdCounts) {
|
for (const [key, value] of global.cmdCounts) {
|
||||||
|
@ -53,5 +52,5 @@ const Global = mongoose.model("Global", globalSchema);
|
||||||
console.log(`Migrated counts for command ${key}`);
|
console.log(`Migrated counts for command ${key}`);
|
||||||
}
|
}
|
||||||
console.log("Done!");
|
console.log("Done!");
|
||||||
return;
|
return process.exit(0);
|
||||||
})();
|
})();
|
7
utils/psqlinit.sh
Normal file
7
utils/psqlinit.sh
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||||
|
CREATE TABLE guilds ( guild_id VARCHAR(30) NOT NULL, tags json NOT NULL, prefix VARCHAR(15) NOT NULL, disabled text ARRAY NOT NULL, tags_disabled boolean NOT NULL );
|
||||||
|
CREATE TABLE counts ( command VARCHAR NOT NULL, count integer NOT NULL );
|
||||||
|
EOSQL
|
Loading…
Add table
Add a link
Reference in a new issue