fix: change BIGINT UNSIGNED to BIGINT, INT columns map to i32 not i64

This commit is contained in:
NixReaper
2026-04-25 20:59:41 -05:00
parent 144d08a581
commit 09b043d764
2 changed files with 63 additions and 63 deletions
+57 -57
View File
@@ -1,12 +1,12 @@
-- Users (panel logins: admin + per-account users) -- Users (panel logins: admin + per-account users)
CREATE TABLE IF NOT EXISTS users ( CREATE TABLE IF NOT EXISTS users (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, id BIGINT NOT NULL AUTO_INCREMENT,
username VARCHAR(64) NOT NULL, username VARCHAR(64) NOT NULL,
email VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL,
password_hash VARCHAR(255) NOT NULL, password_hash VARCHAR(255) NOT NULL,
role ENUM('admin','user') NOT NULL DEFAULT 'user', role ENUM('admin','user') NOT NULL DEFAULT 'user',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id), PRIMARY KEY (id),
UNIQUE KEY uq_username (username), UNIQUE KEY uq_username (username),
UNIQUE KEY uq_email (email) UNIQUE KEY uq_email (email)
@@ -14,18 +14,18 @@ CREATE TABLE IF NOT EXISTS users (
-- Hosting accounts -- Hosting accounts
CREATE TABLE IF NOT EXISTS accounts ( CREATE TABLE IF NOT EXISTS accounts (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, id BIGINT NOT NULL AUTO_INCREMENT,
user_id BIGINT UNSIGNED, user_id BIGINT,
username VARCHAR(64) NOT NULL, username VARCHAR(64) NOT NULL,
domain VARCHAR(255) NOT NULL, domain VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL,
password_hash VARCHAR(255) NOT NULL, password_hash VARCHAR(255) NOT NULL,
package_name VARCHAR(64) NOT NULL DEFAULT 'Default', package_name VARCHAR(64) NOT NULL DEFAULT 'Default',
disk_quota_mb INT NOT NULL DEFAULT 10240, disk_quota_mb INT NOT NULL DEFAULT 10240,
bandwidth_mb INT NOT NULL DEFAULT 0, bandwidth_mb INT NOT NULL DEFAULT 0,
status ENUM('active','suspended','terminated') NOT NULL DEFAULT 'active', status ENUM('active','suspended','terminated') NOT NULL DEFAULT 'active',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id), PRIMARY KEY (id),
UNIQUE KEY uq_username (username), UNIQUE KEY uq_username (username),
UNIQUE KEY uq_domain (domain), UNIQUE KEY uq_domain (domain),
@@ -34,12 +34,12 @@ CREATE TABLE IF NOT EXISTS accounts (
-- Domains / DNS zones -- Domains / DNS zones
CREATE TABLE IF NOT EXISTS domains ( CREATE TABLE IF NOT EXISTS domains (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, id BIGINT NOT NULL AUTO_INCREMENT,
account_id BIGINT UNSIGNED, account_id BIGINT,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
type ENUM('main','addon','parked','subdomain') NOT NULL DEFAULT 'main', type ENUM('main','addon','parked','subdomain') NOT NULL DEFAULT 'main',
status ENUM('active','inactive') NOT NULL DEFAULT 'active', status ENUM('active','inactive') NOT NULL DEFAULT 'active',
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id), PRIMARY KEY (id),
UNIQUE KEY uq_name (name), UNIQUE KEY uq_name (name),
FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
@@ -47,25 +47,25 @@ CREATE TABLE IF NOT EXISTS domains (
-- DNS records -- DNS records
CREATE TABLE IF NOT EXISTS dns_records ( CREATE TABLE IF NOT EXISTS dns_records (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, id BIGINT NOT NULL AUTO_INCREMENT,
domain_id BIGINT UNSIGNED NOT NULL, domain_id BIGINT NOT NULL,
type VARCHAR(10) NOT NULL, -- A, AAAA, CNAME, MX, TXT, NS, SRV type VARCHAR(10) NOT NULL,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
content VARCHAR(512) NOT NULL, content VARCHAR(512) NOT NULL,
ttl INT NOT NULL DEFAULT 3600, ttl INT NOT NULL DEFAULT 3600,
priority INT, priority INT,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id), PRIMARY KEY (id),
FOREIGN KEY (domain_id) REFERENCES domains(id) ON DELETE CASCADE FOREIGN KEY (domain_id) REFERENCES domains(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- MySQL/MariaDB databases owned by accounts -- MySQL/MariaDB databases owned by accounts
CREATE TABLE IF NOT EXISTS account_databases ( CREATE TABLE IF NOT EXISTS account_databases (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, id BIGINT NOT NULL AUTO_INCREMENT,
account_id BIGINT UNSIGNED NOT NULL, account_id BIGINT NOT NULL,
db_name VARCHAR(64) NOT NULL, db_name VARCHAR(64) NOT NULL,
db_user VARCHAR(64) NOT NULL, db_user VARCHAR(64) NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id), PRIMARY KEY (id),
UNIQUE KEY uq_db_name (db_name), UNIQUE KEY uq_db_name (db_name),
FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
@@ -73,12 +73,12 @@ CREATE TABLE IF NOT EXISTS account_databases (
-- Email accounts -- Email accounts
CREATE TABLE IF NOT EXISTS email_accounts ( CREATE TABLE IF NOT EXISTS email_accounts (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, id BIGINT NOT NULL AUTO_INCREMENT,
account_id BIGINT UNSIGNED NOT NULL, account_id BIGINT NOT NULL,
address VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL,
password_hash VARCHAR(255) NOT NULL, password_hash VARCHAR(255) NOT NULL,
quota_mb INT NOT NULL DEFAULT 1024, quota_mb INT NOT NULL DEFAULT 1024,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id), PRIMARY KEY (id),
UNIQUE KEY uq_address (address), UNIQUE KEY uq_address (address),
FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
@@ -86,11 +86,11 @@ CREATE TABLE IF NOT EXISTS email_accounts (
-- FTP accounts -- FTP accounts
CREATE TABLE IF NOT EXISTS ftp_accounts ( CREATE TABLE IF NOT EXISTS ftp_accounts (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, id BIGINT NOT NULL AUTO_INCREMENT,
account_id BIGINT UNSIGNED NOT NULL, account_id BIGINT NOT NULL,
username VARCHAR(64) NOT NULL, username VARCHAR(64) NOT NULL,
home_dir VARCHAR(512) NOT NULL, home_dir VARCHAR(512) NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id), PRIMARY KEY (id),
UNIQUE KEY uq_username (username), UNIQUE KEY uq_username (username),
FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
@@ -98,15 +98,15 @@ CREATE TABLE IF NOT EXISTS ftp_accounts (
-- SSL certificates -- SSL certificates
CREATE TABLE IF NOT EXISTS ssl_certificates ( CREATE TABLE IF NOT EXISTS ssl_certificates (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, id BIGINT NOT NULL AUTO_INCREMENT,
account_id BIGINT UNSIGNED, account_id BIGINT,
domain VARCHAR(255) NOT NULL, domain VARCHAR(255) NOT NULL,
issuer VARCHAR(64) NOT NULL DEFAULT 'letsencrypt', issuer VARCHAR(64) NOT NULL DEFAULT 'letsencrypt',
cert_path VARCHAR(512), cert_path VARCHAR(512),
key_path VARCHAR(512), key_path VARCHAR(512),
expires_at DATETIME, expires_at DATETIME,
auto_renew TINYINT(1) NOT NULL DEFAULT 1, auto_renew TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id), PRIMARY KEY (id),
UNIQUE KEY uq_domain (domain), UNIQUE KEY uq_domain (domain),
FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE SET NULL FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE SET NULL
@@ -114,13 +114,13 @@ CREATE TABLE IF NOT EXISTS ssl_certificates (
-- Backup jobs -- Backup jobs
CREATE TABLE IF NOT EXISTS backups ( CREATE TABLE IF NOT EXISTS backups (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, id BIGINT NOT NULL AUTO_INCREMENT,
account_id BIGINT UNSIGNED, account_id BIGINT,
type ENUM('full','incremental') NOT NULL DEFAULT 'full', type ENUM('full','incremental') NOT NULL DEFAULT 'full',
status ENUM('pending','running','completed','failed') NOT NULL DEFAULT 'pending', status ENUM('pending','running','completed','failed') NOT NULL DEFAULT 'pending',
size_bytes BIGINT, size_bytes BIGINT,
path VARCHAR(512), path VARCHAR(512),
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
completed_at DATETIME, completed_at DATETIME,
PRIMARY KEY (id), PRIMARY KEY (id),
FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE SET NULL FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE SET NULL
+6 -6
View File
@@ -11,8 +11,8 @@ pub struct Account {
pub domain: String, pub domain: String,
pub email: String, pub email: String,
pub package_name: String, pub package_name: String,
pub disk_quota_mb: i64, pub disk_quota_mb: i32, // INT column → i32
pub bandwidth_mb: i64, pub bandwidth_mb: i32, // INT column → i32
pub status: String, pub status: String,
pub created_at: NaiveDateTime, pub created_at: NaiveDateTime,
} }
@@ -24,8 +24,8 @@ pub struct CreateAccountRequest {
pub email: String, pub email: String,
pub password: String, pub password: String,
pub package_name: Option<String>, pub package_name: Option<String>,
pub disk_quota_mb: Option<i64>, pub disk_quota_mb: Option<i32>,
pub bandwidth_mb: Option<i64>, pub bandwidth_mb: Option<i32>,
} }
pub async fn list_accounts( pub async fn list_accounts(
@@ -71,8 +71,8 @@ pub async fn create_account(
let _ = std::fs::create_dir_all(format!("/home/{}/public_html", body.username)); let _ = std::fs::create_dir_all(format!("/home/{}/public_html", body.username));
let package_name = body.package_name.unwrap_or_else(|| "Default".into()); let package_name = body.package_name.unwrap_or_else(|| "Default".into());
let disk_quota_mb = body.disk_quota_mb.unwrap_or(10240); let disk_quota_mb: i32 = body.disk_quota_mb.unwrap_or(10240);
let bandwidth_mb = body.bandwidth_mb.unwrap_or(0); let bandwidth_mb: i32 = body.bandwidth_mb.unwrap_or(0);
let insert_id: u64 = sqlx::query( let insert_id: u64 = sqlx::query(
"INSERT INTO accounts (username, domain, email, password_hash, package_name, disk_quota_mb, bandwidth_mb, status) "INSERT INTO accounts (username, domain, email, password_hash, package_name, disk_quota_mb, bandwidth_mb, status)