Compare commits

..

2 Commits

Author SHA1 Message Date
df0184facf Add migration to update users table schema
Changes:
- Add display_name, email, and groups columns to existing users table
- Handle MariaDB lack of IF NOT EXISTS in ALTER TABLE
- Gracefully skip columns that already exist
- Fixes 500 error when authenticating users

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-07 20:28:47 -05:00
a8be111e04 Allow NULL workflow_id in executions table for quick commands
Changes:
- Modified executions table schema to allow NULL workflow_id
- Removed foreign key constraint that prevented NULL values
- Added migration to update existing table structure
- Quick commands can now be stored without a workflow reference

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-07 20:27:02 -05:00

View File

@@ -46,6 +46,29 @@ async function initDatabase() {
)
`);
// Migrate existing users table to add missing columns
try {
await connection.query(`
ALTER TABLE users
ADD COLUMN IF NOT EXISTS display_name VARCHAR(255) AFTER username,
ADD COLUMN IF NOT EXISTS email VARCHAR(255) AFTER display_name,
ADD COLUMN IF NOT EXISTS groups TEXT AFTER email
`);
console.log('Users table migrated successfully');
} catch (error) {
// MariaDB doesn't support IF NOT EXISTS in ALTER TABLE, try individual columns
try {
await connection.query(`ALTER TABLE users ADD COLUMN display_name VARCHAR(255) AFTER username`);
} catch (e) { /* Column exists */ }
try {
await connection.query(`ALTER TABLE users ADD COLUMN email VARCHAR(255) AFTER display_name`);
} catch (e) { /* Column exists */ }
try {
await connection.query(`ALTER TABLE users ADD COLUMN groups TEXT AFTER email`);
} catch (e) { /* Column exists */ }
console.log('Users table migration completed');
}
await connection.query(`
CREATE TABLE IF NOT EXISTS workers (
id VARCHAR(36) PRIMARY KEY,
@@ -75,19 +98,33 @@ async function initDatabase() {
await connection.query(`
CREATE TABLE IF NOT EXISTS executions (
id VARCHAR(36) PRIMARY KEY,
workflow_id VARCHAR(36) NOT NULL,
workflow_id VARCHAR(36) NULL,
status VARCHAR(50) NOT NULL,
started_by VARCHAR(255),
started_at TIMESTAMP NULL,
completed_at TIMESTAMP NULL,
logs JSON,
FOREIGN KEY (workflow_id) REFERENCES workflows(id) ON DELETE CASCADE,
INDEX idx_workflow (workflow_id),
INDEX idx_status (status),
INDEX idx_started (started_at)
)
`);
// Migrate existing executions table to allow NULL workflow_id
try {
await connection.query(`
ALTER TABLE executions
MODIFY workflow_id VARCHAR(36) NULL,
DROP FOREIGN KEY executions_ibfk_1
`);
console.log('Executions table migrated to allow NULL workflow_id');
} catch (error) {
// Ignore error if foreign key doesn't exist or already modified
if (!error.message.includes('check that column/key exists')) {
console.log('Migration note:', error.message);
}
}
console.log('Database tables initialized successfully');
} catch (error) {
console.error('Database initialization error:', error);