The initialize function now fails if any board already exists.
parent
f78c55e824
commit
034b5cb13e
24
main.go
24
main.go
|
@ -31,7 +31,7 @@ func loadConfig(filename string) (*handlers.Config, error) {
|
|||
func createTablesIfNotExist(db *sql.DB) error {
|
||||
// Create boards table
|
||||
_, err := db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS boards (
|
||||
CREATE TABLE boards (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
|
@ -47,7 +47,7 @@ func createTablesIfNotExist(db *sql.DB) error {
|
|||
|
||||
// Create users table
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
CREATE TABLE users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(255) NOT NULL UNIQUE,
|
||||
display_name VARCHAR(255),
|
||||
|
@ -67,7 +67,7 @@ func createTablesIfNotExist(db *sql.DB) error {
|
|||
|
||||
// Create threads table (without type field)
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS threads (
|
||||
CREATE TABLE threads (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
board_id INT NOT NULL,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
|
@ -83,7 +83,7 @@ func createTablesIfNotExist(db *sql.DB) error {
|
|||
|
||||
// Create posts table
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS posts (
|
||||
CREATE TABLE posts (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
thread_id INT NOT NULL,
|
||||
user_id INT NOT NULL,
|
||||
|
@ -102,7 +102,7 @@ func createTablesIfNotExist(db *sql.DB) error {
|
|||
|
||||
// Create likes table
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS likes (
|
||||
CREATE TABLE likes (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
post_id INT NOT NULL,
|
||||
user_id INT NOT NULL,
|
||||
|
@ -116,7 +116,7 @@ func createTablesIfNotExist(db *sql.DB) error {
|
|||
|
||||
// Create board_permissions table
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS board_permissions (
|
||||
CREATE TABLE board_permissions (
|
||||
user_id INT NOT NULL,
|
||||
board_id INT NOT NULL,
|
||||
permissions BIGINT DEFAULT 0,
|
||||
|
@ -129,7 +129,7 @@ func createTablesIfNotExist(db *sql.DB) error {
|
|||
|
||||
// Create notifications table
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS notifications (
|
||||
CREATE TABLE notifications (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
type VARCHAR(50) NOT NULL,
|
||||
|
@ -143,7 +143,7 @@ func createTablesIfNotExist(db *sql.DB) error {
|
|||
|
||||
// Create reactions table
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS reactions (
|
||||
CREATE TABLE reactions (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
post_id INT NOT NULL,
|
||||
user_id INT NOT NULL,
|
||||
|
@ -156,7 +156,7 @@ func createTablesIfNotExist(db *sql.DB) error {
|
|||
|
||||
// Create reposts table
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS reposts (
|
||||
CREATE TABLE reposts (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
thread_id INT NOT NULL,
|
||||
board_id INT NOT NULL,
|
||||
|
@ -171,7 +171,7 @@ func createTablesIfNotExist(db *sql.DB) error {
|
|||
|
||||
// Create news table
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS news (
|
||||
CREATE TABLE news (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
|
@ -184,7 +184,7 @@ func createTablesIfNotExist(db *sql.DB) error {
|
|||
|
||||
// Create chat_messages table
|
||||
_, err = db.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS chat_messages (
|
||||
CREATE TABLE chat_messages (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id INT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
|
@ -195,7 +195,7 @@ func createTablesIfNotExist(db *sql.DB) error {
|
|||
return fmt.Errorf("error creating chat_messages table: %v", err)
|
||||
}
|
||||
|
||||
log.Println("Database tables created or already exist")
|
||||
log.Println("Database tables created.")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue