60 lines
2.0 KiB
Java
60 lines
2.0 KiB
Java
package src.db;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.Statement;
|
|
|
|
public class Migration {
|
|
public static void run(Connection conn) {
|
|
try (Statement stmt = conn.createStatement()) {
|
|
stmt.execute("""
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
name TEXT NOT NULL,
|
|
email TEXT NOT NULL UNIQUE,
|
|
password_hash TEXT NOT NULL
|
|
)
|
|
""");
|
|
|
|
stmt.execute("""
|
|
CREATE TABLE IF NOT EXISTS accounts (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
owner_id INTEGER NOT NULL,
|
|
type TEXT CHECK(type IN ('CHECKING','SAVINGS','CREDIT')) NOT NULL,
|
|
account_number TEXT NOT NULL UNIQUE,
|
|
bank_code TEXT NOT NULL,
|
|
balance REAL NOT NULL DEFAULT 0,
|
|
FOREIGN KEY(owner_id) REFERENCES users(id)
|
|
)
|
|
""");
|
|
|
|
stmt.execute("""
|
|
CREATE TABLE IF NOT EXISTS giro_accounts (
|
|
id INTEGER PRIMARY KEY,
|
|
overdraft_limit REAL DEFAULT 0,
|
|
FOREIGN KEY(id) REFERENCES accounts(id) ON DELETE CASCADE
|
|
)
|
|
""");
|
|
|
|
stmt.execute("""
|
|
CREATE TABLE IF NOT EXISTS spar_accounts (
|
|
id INTEGER PRIMARY KEY,
|
|
interest_rate REAL DEFAULT 0,
|
|
FOREIGN KEY(id) REFERENCES accounts(id) ON DELETE CASCADE
|
|
)
|
|
""");
|
|
|
|
stmt.execute("""
|
|
CREATE TABLE IF NOT EXISTS kredit_accounts (
|
|
id INTEGER PRIMARY KEY,
|
|
credit_limit REAL DEFAULT 0,
|
|
repayment_plan TEXT,
|
|
FOREIGN KEY(id) REFERENCES accounts(id) ON DELETE CASCADE
|
|
)
|
|
""");
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|