Fix database initialization connection leaks
All checks were successful
Build and Push Container / build-and-push (push) Successful in 2m18s
All checks were successful
Build and Push Container / build-and-push (push) Successful in 2m18s
This commit is contained in:
parent
b92a2fff97
commit
5197c9abf8
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/guild_management"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/exts/logging"
|
||||
@ -13,6 +12,7 @@ import (
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/postgres"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/internal/services"
|
||||
"gitea.wayfinderak.com/wayfinderak/goff/pkg/email"
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
|
||||
//"github.com/MikeModder/anpan"
|
||||
"os"
|
||||
@ -124,6 +124,7 @@ func getPrefixes(guildID string) []string {
|
||||
log.Println(err)
|
||||
return []string{"Go.", "go."}
|
||||
}
|
||||
defer rows.Close()
|
||||
var prefixes []string
|
||||
for rows.Next() {
|
||||
var prefix string
|
||||
|
||||
@ -33,7 +33,7 @@ func ConnectDatabase(dbConnString string) {
|
||||
}
|
||||
|
||||
func InitializeDatabase() {
|
||||
_, err := DB.Query("CREATE TABLE IF NOT EXISTS users(" +
|
||||
_, err := DB.Exec("CREATE TABLE IF NOT EXISTS users(" +
|
||||
"id varchar(30) primary key," +
|
||||
"banned bool not null default false," +
|
||||
"logging bool not null default true," +
|
||||
@ -45,7 +45,7 @@ func InitializeDatabase() {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Query("CREATE TABLE IF NOT EXISTS guilds(" +
|
||||
_, err = DB.Exec("CREATE TABLE IF NOT EXISTS guilds(" +
|
||||
"id varchar(30) primary key," +
|
||||
"welcome_message varchar(1000) NOT NULL DEFAULT ''," +
|
||||
"goodbye_message varchar(1000) NOT NULL DEFAULT ''," +
|
||||
@ -55,14 +55,14 @@ func InitializeDatabase() {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Query("CREATE TABLE IF NOT EXISTS prefixes(" +
|
||||
_, err = DB.Exec("CREATE TABLE IF NOT EXISTS prefixes(" +
|
||||
"id serial primary key," +
|
||||
"prefix varchar(10) not null unique default 'Go.'" +
|
||||
")")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Query("CREATE TABLE IF NOT EXISTS tags(" +
|
||||
_, err = DB.Exec("CREATE TABLE IF NOT EXISTS tags(" +
|
||||
"id serial primary key," +
|
||||
"tag varchar(100) not null unique," +
|
||||
"content varchar(1000) not null," +
|
||||
@ -73,21 +73,21 @@ func InitializeDatabase() {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Query("CREATE TABLE IF NOT EXISTS x_users_guilds(" +
|
||||
_, err = DB.Exec("CREATE TABLE IF NOT EXISTS x_users_guilds(" +
|
||||
"guild_id varchar(30) not null references guilds(id)," +
|
||||
"user_id varchar(30) not null references users(id)" +
|
||||
")")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Query("CREATE TABLE IF NOT EXISTS x_guilds_prefixes(" +
|
||||
_, err = DB.Exec("CREATE TABLE IF NOT EXISTS x_guilds_prefixes(" +
|
||||
"guild_id varchar(30) not null references guilds(id)," +
|
||||
"prefix_id int not null references prefixes(id)" +
|
||||
")")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Query("CREATE TABLE IF NOT EXISTS tasks(" +
|
||||
_, err = DB.Exec("CREATE TABLE IF NOT EXISTS tasks(" +
|
||||
"id serial primary key," +
|
||||
"type varchar(10) not null," +
|
||||
"content text not null," +
|
||||
@ -101,7 +101,7 @@ func InitializeDatabase() {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Query(`CREATE TABLE IF NOT EXISTS postfixes(
|
||||
_, err = DB.Exec(`CREATE TABLE IF NOT EXISTS postfixes(
|
||||
id serial primary key,
|
||||
name varchar(100) not null,
|
||||
time timestamp not null default NOW())`)
|
||||
@ -126,37 +126,37 @@ func InitializeDatabase() {
|
||||
}
|
||||
|
||||
func LoadTestData() {
|
||||
_, err := DB.Query("INSERT INTO users (id, banned, logging, steam_id, is_active, is_staff, is_admin) values " +
|
||||
_, err := DB.Exec("INSERT INTO users (id, banned, logging, steam_id, is_active, is_staff, is_admin) values " +
|
||||
"('351794468870946827', false, true, '76561198024193239', true, true, true)," +
|
||||
"('692908139506434065', false, true, '', true, false, false)," +
|
||||
"('396588996706304010', false, true, '', true, true, false)")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Query("INSERT INTO guilds (id, welcome_message, goodbye_message) VALUES " +
|
||||
_, err = DB.Exec("INSERT INTO guilds (id, welcome_message, goodbye_message) VALUES " +
|
||||
"('265828729970753537', 'Hey there is someone new here.', 'Well fine then... Just leave without saying goodbye')")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Query("INSERT INTO prefixes (prefix) VALUES ('Godev.'), ('godev.'), ('godev,')")
|
||||
_, err = DB.Exec("INSERT INTO prefixes (prefix) VALUES ('Godev.'), ('godev.'), ('godev,')")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Query("INSERT INTO x_users_guilds (guild_id, user_id) VALUES " +
|
||||
_, err = DB.Exec("INSERT INTO x_users_guilds (guild_id, user_id) VALUES " +
|
||||
"('265828729970753537', '351794468870946827')," +
|
||||
"('265828729970753537', '692908139506434065')," +
|
||||
"('265828729970753537', '396588996706304010')")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Query("INSERT INTO x_guilds_prefixes (guild_id, prefix_id) VALUES " +
|
||||
_, err = DB.Exec("INSERT INTO x_guilds_prefixes (guild_id, prefix_id) VALUES " +
|
||||
"('265828729970753537', 1)," +
|
||||
"('265828729970753537', 2)," +
|
||||
"('265828729970753537', 3)")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
_, err = DB.Query("INSERT INTO tags (tag, content, creator, guild_id) VALUES " +
|
||||
_, err = DB.Exec("INSERT INTO tags (tag, content, creator, guild_id) VALUES " +
|
||||
"('test', 'This is a test of the tag system', '351794468870946827', '265828729970753537')")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
||||
@ -47,8 +47,10 @@ func RunPostfixes() {
|
||||
continue
|
||||
}
|
||||
if rows.Next() {
|
||||
rows.Close()
|
||||
continue
|
||||
} else {
|
||||
rows.Close()
|
||||
err := postfix.Invoke(false)
|
||||
if err != nil {
|
||||
continue
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user