Refactoring continues.
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
templateHelpers "synlotto-website/internal/helpers/template"
|
templateHelpers "synlotto-website/internal/helpers/template"
|
||||||
services "synlotto-website/services/tickets"
|
services "synlotto-website/internal/services/tickets"
|
||||||
|
|
||||||
"synlotto-website/internal/models"
|
"synlotto-website/internal/models"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
httpHelpers "synlotto-website/internal/helpers/http"
|
httpHelpers "synlotto-website/internal/helpers/http"
|
||||||
securityHelpers "synlotto-website/internal/helpers/security"
|
securityHelpers "synlotto-website/internal/helpers/security"
|
||||||
templateHelpers "synlotto-website/internal/helpers/template"
|
templateHelpers "synlotto-website/internal/helpers/template"
|
||||||
draws "synlotto-website/services/draws"
|
draws "synlotto-website/internal/services/draws"
|
||||||
|
|
||||||
"synlotto-website/internal/helpers"
|
"synlotto-website/internal/helpers"
|
||||||
"synlotto-website/internal/models"
|
"synlotto-website/internal/models"
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
templateHandlers "synlotto-website/internal/handlers/template"
|
templateHandlers "synlotto-website/internal/handlers/template"
|
||||||
"synlotto-website/internal/helpers"
|
|
||||||
httpHelpers "synlotto-website/internal/helpers/http"
|
httpHelpers "synlotto-website/internal/helpers/http"
|
||||||
securityHelpers "synlotto-website/internal/helpers/security"
|
securityHelpers "synlotto-website/internal/helpers/security"
|
||||||
templateHelpers "synlotto-website/internal/helpers/template"
|
templateHelpers "synlotto-website/internal/helpers/template"
|
||||||
|
|
||||||
"synlotto-website/internal/storage"
|
"synlotto-website/internal/helpers"
|
||||||
|
storage "synlotto-website/internal/storage/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MessagesInboxHandler(db *sql.DB) http.HandlerFunc {
|
func MessagesInboxHandler(db *sql.DB) http.HandlerFunc {
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"synlotto-website/config"
|
|
||||||
helpers "synlotto-website/internal/helpers/http"
|
helpers "synlotto-website/internal/helpers/http"
|
||||||
"synlotto-website/internal/models"
|
"synlotto-website/internal/models"
|
||||||
|
"synlotto-website/internal/platform/config"
|
||||||
|
|
||||||
"github.com/gorilla/csrf"
|
"github.com/gorilla/csrf"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import (
|
|||||||
sessionHandlers "synlotto-website/internal/handlers/session"
|
sessionHandlers "synlotto-website/internal/handlers/session"
|
||||||
sessionHelpers "synlotto-website/internal/helpers/session"
|
sessionHelpers "synlotto-website/internal/helpers/session"
|
||||||
|
|
||||||
|
"synlotto-website/internal/logging"
|
||||||
"synlotto-website/internal/models"
|
"synlotto-website/internal/models"
|
||||||
"synlotto-website/logging"
|
|
||||||
|
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package matcher
|
package services
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"synlotto-website/internal/helpers"
|
"synlotto-website/internal/helpers"
|
||||||
"synlotto-website/internal/models"
|
"synlotto-website/internal/models"
|
||||||
thunderballRules "synlotto-website/rules"
|
thunderballRules "synlotto-website/internal/rules/thunderball"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MatchTicketToDraw(ticket models.MatchTicket, draw models.DrawResult, rules []models.PrizeRule, db *sql.DB) models.MatchResult {
|
func MatchTicketToDraw(ticket models.MatchTicket, draw models.DrawResult, rules []models.PrizeRule, db *sql.DB) models.MatchResult {
|
||||||
|
|||||||
@@ -6,12 +6,11 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
|
|
||||||
lotteryTicketHandlers "synlotto-website/internal/handlers/lottery/tickets"
|
lotteryTicketHandlers "synlotto-website/internal/handlers/lottery/tickets"
|
||||||
thunderballrules "synlotto-website/rules"
|
thunderballrules "synlotto-website/internal/rules/thunderball"
|
||||||
services "synlotto-website/services/draws"
|
services "synlotto-website/internal/services/draws"
|
||||||
|
|
||||||
"synlotto-website/internal/helpers"
|
"synlotto-website/internal/helpers"
|
||||||
"synlotto-website/internal/models"
|
"synlotto-website/internal/models"
|
||||||
"synlotto-website/matcher"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func RunTicketMatching(db *sql.DB, triggeredBy string) (models.MatchRunStats, error) {
|
func RunTicketMatching(db *sql.DB, triggeredBy string) (models.MatchRunStats, error) {
|
||||||
|
|||||||
@@ -1 +1,238 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
|
const SchemaUsers = `
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
username TEXT NOT NULL UNIQUE,
|
||||||
|
password_hash TEXT NOT NULL,
|
||||||
|
is_admin BOOLEAN
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaThunderballResults = `
|
||||||
|
CREATE TABLE IF NOT EXISTS results_thunderball (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
draw_date TEXT NOT NULL UNIQUE,
|
||||||
|
draw_id INTEGER NOT NULL UNIQUE,
|
||||||
|
machine TEXT,
|
||||||
|
ballset TEXT,
|
||||||
|
ball1 INTEGER,
|
||||||
|
ball2 INTEGER,
|
||||||
|
ball3 INTEGER,
|
||||||
|
ball4 INTEGER,
|
||||||
|
ball5 INTEGER,
|
||||||
|
thunderball INTEGER
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaThunderballPrizes = `
|
||||||
|
CREATE TABLE IF NOT EXISTS prizes_thunderball (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
draw_id INTEGER NOT NULL,
|
||||||
|
draw_date TEXT,
|
||||||
|
prize1 TEXT,
|
||||||
|
prize1_winners INTEGER,
|
||||||
|
prize1_per_winner INTEGER,
|
||||||
|
prize1_fund INTEGER,
|
||||||
|
prize2 TEXT,
|
||||||
|
prize2_winners INTEGER,
|
||||||
|
prize2_per_winner INTEGER,
|
||||||
|
prize2_fund INTEGER,
|
||||||
|
prize3 TEXT,
|
||||||
|
prize3_winners INTEGER,
|
||||||
|
prize3_per_winner INTEGER,
|
||||||
|
prize3_fund INTEGER,
|
||||||
|
prize4 TEXT,
|
||||||
|
prize4_winners INTEGER,
|
||||||
|
prize4_per_winner INTEGER,
|
||||||
|
prize4_fund INTEGER,
|
||||||
|
prize5 TEXT,
|
||||||
|
prize5_winners INTEGER,
|
||||||
|
prize5_per_winner INTEGER,
|
||||||
|
prize5_fund INTEGER,
|
||||||
|
prize6 TEXT,
|
||||||
|
prize6_winners INTEGER,
|
||||||
|
prize6_per_winner INTEGER,
|
||||||
|
prize6_fund INTEGER,
|
||||||
|
prize7 TEXT,
|
||||||
|
prize7_winners INTEGER,
|
||||||
|
prize7_per_winner INTEGER,
|
||||||
|
prize7_fund INTEGER,
|
||||||
|
prize8 TEXT,
|
||||||
|
prize8_winners INTEGER,
|
||||||
|
prize8_per_winner INTEGER,
|
||||||
|
prize8_fund INTEGER,
|
||||||
|
prize9 TEXT,
|
||||||
|
prize9_winners INTEGER,
|
||||||
|
prize9_per_winner INTEGER,
|
||||||
|
prize9_fund INTEGER,
|
||||||
|
total_winners INTEGER,
|
||||||
|
total_prize_fund INTEGER,
|
||||||
|
FOREIGN KEY (draw_date) REFERENCES results_thunderball(draw_date)
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaLottoResults = `
|
||||||
|
CREATE TABLE IF NOT EXISTS results_lotto (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
draw_date TEXT NOT NULL UNIQUE,
|
||||||
|
draw_id INTEGER NOT NULL UNIQUE,
|
||||||
|
machine TEXT,
|
||||||
|
ballset TEXT,
|
||||||
|
ball1 INTEGER,
|
||||||
|
ball2 INTEGER,
|
||||||
|
ball3 INTEGER,
|
||||||
|
ball4 INTEGER,
|
||||||
|
ball5 INTEGER,
|
||||||
|
ball6 INTEGER,
|
||||||
|
bonusball INTEGER
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaMyTickets = `
|
||||||
|
CREATE TABLE IF NOT EXISTS my_tickets (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
userId INTEGER NOT NULL,
|
||||||
|
game_type TEXT NOT NULL,
|
||||||
|
draw_date TEXT NOT NULL,
|
||||||
|
ball1 INTEGER,
|
||||||
|
ball2 INTEGER,
|
||||||
|
ball3 INTEGER,
|
||||||
|
ball4 INTEGER,
|
||||||
|
ball5 INTEGER,
|
||||||
|
ball6 INTEGER,
|
||||||
|
bonus1 INTEGER,
|
||||||
|
bonus2 INTEGER,
|
||||||
|
duplicate BOOLEAN DEFAULT 0,
|
||||||
|
purchase_date TEXT,
|
||||||
|
purchase_method TEXT,
|
||||||
|
image_path TEXT,
|
||||||
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
matched_main INTEGER,
|
||||||
|
matched_bonus INTEGER,
|
||||||
|
prize_tier TEXT,
|
||||||
|
is_winner BOOLEAN,
|
||||||
|
prize_amount INTEGER,
|
||||||
|
prize_label TEXT,
|
||||||
|
syndicate_id INTEGER,
|
||||||
|
FOREIGN KEY (userId) REFERENCES users(id)
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaUsersMessages = `
|
||||||
|
CREATE TABLE IF NOT EXISTS users_messages (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
senderId INTEGER NOT NULL REFERENCES users(id),
|
||||||
|
recipientId INTEGER NOT NULL REFERENCES users(id),
|
||||||
|
subject TEXT NOT NULL,
|
||||||
|
message TEXT,
|
||||||
|
is_read BOOLEAN DEFAULT FALSE,
|
||||||
|
is_archived BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
archived_at TIMESTAMP
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaUsersNotifications = `
|
||||||
|
CREATE TABLE IF NOT EXISTS users_notification (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
user_id INTEGER NOT NULL REFERENCES users(id),
|
||||||
|
subject TEXT,
|
||||||
|
body TEXT,
|
||||||
|
is_read BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaAuditLog = `
|
||||||
|
CREATE TABLE IF NOT EXISTS auditlog (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
username TEXT,
|
||||||
|
success INTEGER,
|
||||||
|
timestamp TEXT
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaLogTicketMatching = `
|
||||||
|
CREATE TABLE IF NOT EXISTS log_ticket_matching (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
triggered_by TEXT,
|
||||||
|
run_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
tickets_matched INTEGER,
|
||||||
|
winners_found INTEGER,
|
||||||
|
notes TEXT
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaAdminAccessLog = `
|
||||||
|
CREATE TABLE IF NOT EXISTS admin_access_log (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
user_id INTEGER,
|
||||||
|
accessed_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
path TEXT,
|
||||||
|
ip TEXT,
|
||||||
|
user_agent TEXT
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaNewAuditLog = `
|
||||||
|
CREATE TABLE IF NOT EXISTS audit_log (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
user_id INTEGER,
|
||||||
|
username TEXT,
|
||||||
|
action TEXT,
|
||||||
|
path TEXT,
|
||||||
|
ip TEXT,
|
||||||
|
user_agent TEXT,
|
||||||
|
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaAuditLogin = `
|
||||||
|
CREATE TABLE IF NOT EXISTS audit_login (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
username TEXT,
|
||||||
|
success BOOLEAN,
|
||||||
|
ip TEXT,
|
||||||
|
user_agent TEXT,
|
||||||
|
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaSyndicates = `
|
||||||
|
CREATE TABLE IF NOT EXISTS syndicates (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
owner_id INTEGER NOT NULL,
|
||||||
|
join_code TEXT UNIQUE,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (owner_id) REFERENCES users(id)
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaSyndicateMembers = `
|
||||||
|
CREATE TABLE IF NOT EXISTS syndicate_members (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
syndicate_id INTEGER NOT NULL,
|
||||||
|
user_id INTEGER NOT NULL,
|
||||||
|
role TEXT DEFAULT 'member', -- owner, manager, member
|
||||||
|
status TEXT DEFAULT 'active',
|
||||||
|
joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (syndicate_id) REFERENCES syndicates(id),
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaSyndicateInvites = `
|
||||||
|
CREATE TABLE IF NOT EXISTS syndicate_invites (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
syndicate_id INTEGER NOT NULL,
|
||||||
|
invited_user_id INTEGER NOT NULL,
|
||||||
|
sent_by_user_id INTEGER NOT NULL,
|
||||||
|
status TEXT DEFAULT 'pending',
|
||||||
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY(syndicate_id) REFERENCES syndicates(id),
|
||||||
|
FOREIGN KEY(invited_user_id) REFERENCES users(id)
|
||||||
|
);`
|
||||||
|
|
||||||
|
const SchemaSyndicateInviteTokens = `
|
||||||
|
CREATE TABLE IF NOT EXISTS syndicate_invite_tokens (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
syndicate_id INTEGER NOT NULL,
|
||||||
|
token TEXT NOT NULL UNIQUE,
|
||||||
|
invited_by_user_id INTEGER NOT NULL,
|
||||||
|
accepted_by_user_id INTEGER,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
accepted_at TIMESTAMP,
|
||||||
|
expires_at TIMESTAMP,
|
||||||
|
FOREIGN KEY (syndicate_id) REFERENCES syndicates(id),
|
||||||
|
FOREIGN KEY (invited_by_user_id) REFERENCES users(id),
|
||||||
|
FOREIGN KEY (accepted_by_user_id) REFERENCES users(id)
|
||||||
|
);`
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
|
// ToDo: See these are queries, alot of the others are functions with queries in, remove the functions and lea\ve the sql?...
|
||||||
// ToDo: The last seen statistic is done in days, maybe change or add in how many draws x days ways for ease.
|
// ToDo: The last seen statistic is done in days, maybe change or add in how many draws x days ways for ease.
|
||||||
// Top 5 main numbers since inception of the game.
|
// Top 5 main numbers since inception of the game.
|
||||||
const top5AllTime = `
|
const top5AllTime = `
|
||||||
@@ -1,238 +0,0 @@
|
|||||||
package storage
|
|
||||||
|
|
||||||
const SchemaUsers = `
|
|
||||||
CREATE TABLE IF NOT EXISTS users (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
username TEXT NOT NULL UNIQUE,
|
|
||||||
password_hash TEXT NOT NULL,
|
|
||||||
is_admin BOOLEAN
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaThunderballResults = `
|
|
||||||
CREATE TABLE IF NOT EXISTS results_thunderball (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
draw_date TEXT NOT NULL UNIQUE,
|
|
||||||
draw_id INTEGER NOT NULL UNIQUE,
|
|
||||||
machine TEXT,
|
|
||||||
ballset TEXT,
|
|
||||||
ball1 INTEGER,
|
|
||||||
ball2 INTEGER,
|
|
||||||
ball3 INTEGER,
|
|
||||||
ball4 INTEGER,
|
|
||||||
ball5 INTEGER,
|
|
||||||
thunderball INTEGER
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaThunderballPrizes = `
|
|
||||||
CREATE TABLE IF NOT EXISTS prizes_thunderball (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
draw_id INTEGER NOT NULL,
|
|
||||||
draw_date TEXT,
|
|
||||||
prize1 TEXT,
|
|
||||||
prize1_winners INTEGER,
|
|
||||||
prize1_per_winner INTEGER,
|
|
||||||
prize1_fund INTEGER,
|
|
||||||
prize2 TEXT,
|
|
||||||
prize2_winners INTEGER,
|
|
||||||
prize2_per_winner INTEGER,
|
|
||||||
prize2_fund INTEGER,
|
|
||||||
prize3 TEXT,
|
|
||||||
prize3_winners INTEGER,
|
|
||||||
prize3_per_winner INTEGER,
|
|
||||||
prize3_fund INTEGER,
|
|
||||||
prize4 TEXT,
|
|
||||||
prize4_winners INTEGER,
|
|
||||||
prize4_per_winner INTEGER,
|
|
||||||
prize4_fund INTEGER,
|
|
||||||
prize5 TEXT,
|
|
||||||
prize5_winners INTEGER,
|
|
||||||
prize5_per_winner INTEGER,
|
|
||||||
prize5_fund INTEGER,
|
|
||||||
prize6 TEXT,
|
|
||||||
prize6_winners INTEGER,
|
|
||||||
prize6_per_winner INTEGER,
|
|
||||||
prize6_fund INTEGER,
|
|
||||||
prize7 TEXT,
|
|
||||||
prize7_winners INTEGER,
|
|
||||||
prize7_per_winner INTEGER,
|
|
||||||
prize7_fund INTEGER,
|
|
||||||
prize8 TEXT,
|
|
||||||
prize8_winners INTEGER,
|
|
||||||
prize8_per_winner INTEGER,
|
|
||||||
prize8_fund INTEGER,
|
|
||||||
prize9 TEXT,
|
|
||||||
prize9_winners INTEGER,
|
|
||||||
prize9_per_winner INTEGER,
|
|
||||||
prize9_fund INTEGER,
|
|
||||||
total_winners INTEGER,
|
|
||||||
total_prize_fund INTEGER,
|
|
||||||
FOREIGN KEY (draw_date) REFERENCES results_thunderball(draw_date)
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaLottoResults = `
|
|
||||||
CREATE TABLE IF NOT EXISTS results_lotto (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
draw_date TEXT NOT NULL UNIQUE,
|
|
||||||
draw_id INTEGER NOT NULL UNIQUE,
|
|
||||||
machine TEXT,
|
|
||||||
ballset TEXT,
|
|
||||||
ball1 INTEGER,
|
|
||||||
ball2 INTEGER,
|
|
||||||
ball3 INTEGER,
|
|
||||||
ball4 INTEGER,
|
|
||||||
ball5 INTEGER,
|
|
||||||
ball6 INTEGER,
|
|
||||||
bonusball INTEGER
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaMyTickets = `
|
|
||||||
CREATE TABLE IF NOT EXISTS my_tickets (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
userId INTEGER NOT NULL,
|
|
||||||
game_type TEXT NOT NULL,
|
|
||||||
draw_date TEXT NOT NULL,
|
|
||||||
ball1 INTEGER,
|
|
||||||
ball2 INTEGER,
|
|
||||||
ball3 INTEGER,
|
|
||||||
ball4 INTEGER,
|
|
||||||
ball5 INTEGER,
|
|
||||||
ball6 INTEGER,
|
|
||||||
bonus1 INTEGER,
|
|
||||||
bonus2 INTEGER,
|
|
||||||
duplicate BOOLEAN DEFAULT 0,
|
|
||||||
purchase_date TEXT,
|
|
||||||
purchase_method TEXT,
|
|
||||||
image_path TEXT,
|
|
||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
matched_main INTEGER,
|
|
||||||
matched_bonus INTEGER,
|
|
||||||
prize_tier TEXT,
|
|
||||||
is_winner BOOLEAN,
|
|
||||||
prize_amount INTEGER,
|
|
||||||
prize_label TEXT,
|
|
||||||
syndicate_id INTEGER,
|
|
||||||
FOREIGN KEY (userId) REFERENCES users(id)
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaUsersMessages = `
|
|
||||||
CREATE TABLE IF NOT EXISTS users_messages (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
senderId INTEGER NOT NULL REFERENCES users(id),
|
|
||||||
recipientId INTEGER NOT NULL REFERENCES users(id),
|
|
||||||
subject TEXT NOT NULL,
|
|
||||||
message TEXT,
|
|
||||||
is_read BOOLEAN DEFAULT FALSE,
|
|
||||||
is_archived BOOLEAN DEFAULT FALSE,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
archived_at TIMESTAMP
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaUsersNotifications = `
|
|
||||||
CREATE TABLE IF NOT EXISTS users_notification (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
user_id INTEGER NOT NULL REFERENCES users(id),
|
|
||||||
subject TEXT,
|
|
||||||
body TEXT,
|
|
||||||
is_read BOOLEAN DEFAULT FALSE,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaAuditLog = `
|
|
||||||
CREATE TABLE IF NOT EXISTS auditlog (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
username TEXT,
|
|
||||||
success INTEGER,
|
|
||||||
timestamp TEXT
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaLogTicketMatching = `
|
|
||||||
CREATE TABLE IF NOT EXISTS log_ticket_matching (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
triggered_by TEXT,
|
|
||||||
run_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
tickets_matched INTEGER,
|
|
||||||
winners_found INTEGER,
|
|
||||||
notes TEXT
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaAdminAccessLog = `
|
|
||||||
CREATE TABLE IF NOT EXISTS admin_access_log (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
user_id INTEGER,
|
|
||||||
accessed_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
path TEXT,
|
|
||||||
ip TEXT,
|
|
||||||
user_agent TEXT
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaNewAuditLog = `
|
|
||||||
CREATE TABLE IF NOT EXISTS audit_log (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
user_id INTEGER,
|
|
||||||
username TEXT,
|
|
||||||
action TEXT,
|
|
||||||
path TEXT,
|
|
||||||
ip TEXT,
|
|
||||||
user_agent TEXT,
|
|
||||||
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaAuditLogin = `
|
|
||||||
CREATE TABLE IF NOT EXISTS audit_login (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
username TEXT,
|
|
||||||
success BOOLEAN,
|
|
||||||
ip TEXT,
|
|
||||||
user_agent TEXT,
|
|
||||||
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaSyndicates = `
|
|
||||||
CREATE TABLE IF NOT EXISTS syndicates (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
description TEXT,
|
|
||||||
owner_id INTEGER NOT NULL,
|
|
||||||
join_code TEXT UNIQUE,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (owner_id) REFERENCES users(id)
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaSyndicateMembers = `
|
|
||||||
CREATE TABLE IF NOT EXISTS syndicate_members (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
syndicate_id INTEGER NOT NULL,
|
|
||||||
user_id INTEGER NOT NULL,
|
|
||||||
role TEXT DEFAULT 'member', -- owner, manager, member
|
|
||||||
status TEXT DEFAULT 'active',
|
|
||||||
joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (syndicate_id) REFERENCES syndicates(id),
|
|
||||||
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaSyndicateInvites = `
|
|
||||||
CREATE TABLE IF NOT EXISTS syndicate_invites (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
syndicate_id INTEGER NOT NULL,
|
|
||||||
invited_user_id INTEGER NOT NULL,
|
|
||||||
sent_by_user_id INTEGER NOT NULL,
|
|
||||||
status TEXT DEFAULT 'pending',
|
|
||||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY(syndicate_id) REFERENCES syndicates(id),
|
|
||||||
FOREIGN KEY(invited_user_id) REFERENCES users(id)
|
|
||||||
);`
|
|
||||||
|
|
||||||
const SchemaSyndicateInviteTokens = `
|
|
||||||
CREATE TABLE IF NOT EXISTS syndicate_invite_tokens (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
syndicate_id INTEGER NOT NULL,
|
|
||||||
token TEXT NOT NULL UNIQUE,
|
|
||||||
invited_by_user_id INTEGER NOT NULL,
|
|
||||||
accepted_by_user_id INTEGER,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
accepted_at TIMESTAMP,
|
|
||||||
expires_at TIMESTAMP,
|
|
||||||
FOREIGN KEY (syndicate_id) REFERENCES syndicates(id),
|
|
||||||
FOREIGN KEY (invited_by_user_id) REFERENCES users(id),
|
|
||||||
FOREIGN KEY (accepted_by_user_id) REFERENCES users(id)
|
|
||||||
);`
|
|
||||||
Reference in New Issue
Block a user