mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
Merge migrations
This commit is contained in:
@@ -15,70 +15,65 @@ var migrations = []Migration{
|
|||||||
{
|
{
|
||||||
Version: 1,
|
Version: 1,
|
||||||
SQL: `
|
SQL: `
|
||||||
-- Create users table
|
-- Create users table
|
||||||
CREATE TABLE IF NOT EXISTS users (
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
email TEXT NOT NULL UNIQUE,
|
email TEXT NOT NULL UNIQUE,
|
||||||
display_name TEXT,
|
display_name TEXT,
|
||||||
password_hash TEXT NOT NULL,
|
password_hash TEXT NOT NULL,
|
||||||
role TEXT NOT NULL CHECK(role IN ('admin', 'editor', 'viewer')),
|
role TEXT NOT NULL CHECK(role IN ('admin', 'editor', 'viewer')),
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
last_workspace_id INTEGER
|
last_workspace_id INTEGER
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Create workspaces table with integrated settings
|
-- Create workspaces table with integrated settings
|
||||||
CREATE TABLE IF NOT EXISTS workspaces (
|
CREATE TABLE IF NOT EXISTS workspaces (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
user_id INTEGER NOT NULL,
|
user_id INTEGER NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
last_opened_file_path TEXT,
|
last_opened_file_path TEXT,
|
||||||
-- Settings fields
|
-- Settings fields
|
||||||
theme TEXT NOT NULL DEFAULT 'light' CHECK(theme IN ('light', 'dark')),
|
theme TEXT NOT NULL DEFAULT 'light' CHECK(theme IN ('light', 'dark')),
|
||||||
auto_save BOOLEAN NOT NULL DEFAULT 0,
|
auto_save BOOLEAN NOT NULL DEFAULT 0,
|
||||||
git_enabled BOOLEAN NOT NULL DEFAULT 0,
|
git_enabled BOOLEAN NOT NULL DEFAULT 0,
|
||||||
git_url TEXT,
|
git_url TEXT,
|
||||||
git_user TEXT,
|
git_user TEXT,
|
||||||
git_token TEXT,
|
git_token TEXT,
|
||||||
git_auto_commit BOOLEAN NOT NULL DEFAULT 0,
|
git_auto_commit BOOLEAN NOT NULL DEFAULT 0,
|
||||||
git_commit_msg_template TEXT DEFAULT '${action} ${filename}',
|
git_commit_msg_template TEXT DEFAULT '${action} ${filename}',
|
||||||
FOREIGN KEY (user_id) REFERENCES users (id)
|
git_commit_name TEXT,
|
||||||
);
|
git_commit_email TEXT,
|
||||||
`,
|
show_hidden_files BOOLEAN NOT NULL DEFAULT 0,
|
||||||
},
|
created_by INTEGER REFERENCES users(id),
|
||||||
{
|
updated_by INTEGER REFERENCES users(id),
|
||||||
Version: 2,
|
updated_at TIMESTAMP,
|
||||||
SQL: `
|
FOREIGN KEY (user_id) REFERENCES users (id)
|
||||||
-- Create sessions table for authentication
|
);
|
||||||
CREATE TABLE IF NOT EXISTS sessions (
|
|
||||||
id TEXT PRIMARY KEY,
|
|
||||||
user_id INTEGER NOT NULL,
|
|
||||||
refresh_token TEXT NOT NULL,
|
|
||||||
expires_at TIMESTAMP NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Add show_hidden_files field to workspaces
|
-- Create sessions table for authentication
|
||||||
ALTER TABLE workspaces ADD COLUMN show_hidden_files BOOLEAN NOT NULL DEFAULT 0;
|
CREATE TABLE IF NOT EXISTS sessions (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
user_id INTEGER NOT NULL,
|
||||||
|
refresh_token TEXT NOT NULL,
|
||||||
|
expires_at TIMESTAMP NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
-- Add indexes for performance
|
-- Create system_settings table for application settings
|
||||||
CREATE INDEX idx_sessions_user_id ON sessions(user_id);
|
CREATE TABLE IF NOT EXISTS system_settings (
|
||||||
CREATE INDEX idx_sessions_expires_at ON sessions(expires_at);
|
key TEXT PRIMARY KEY,
|
||||||
CREATE INDEX idx_sessions_refresh_token ON sessions(refresh_token);
|
value TEXT NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
-- Add audit fields to workspaces
|
-- Create indexes for performance
|
||||||
ALTER TABLE workspaces ADD COLUMN created_by INTEGER REFERENCES users(id);
|
CREATE INDEX idx_sessions_user_id ON sessions(user_id);
|
||||||
ALTER TABLE workspaces ADD COLUMN updated_by INTEGER REFERENCES users(id);
|
CREATE INDEX idx_sessions_expires_at ON sessions(expires_at);
|
||||||
ALTER TABLE workspaces ADD COLUMN updated_at TIMESTAMP;
|
CREATE INDEX idx_sessions_refresh_token ON sessions(refresh_token);
|
||||||
|
`,
|
||||||
-- Create system_settings table for application settings
|
|
||||||
CREATE TABLE IF NOT EXISTS system_settings (
|
|
||||||
key TEXT PRIMARY KEY,
|
|
||||||
value TEXT NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
||||||
);`,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user