database_migration.sql•1.71 kB
-- Database migration script for Railway MCP Server
-- Run this in your Supabase PostgreSQL database
-- Create railway_users table (separate from Supabase auth.users)
CREATE TABLE IF NOT EXISTS railway_users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
salt VARCHAR(255) NOT NULL,
username VARCHAR(100) UNIQUE NOT NULL,
full_name VARCHAR(255),
is_active BOOLEAN DEFAULT true,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
last_login TIMESTAMP WITH TIME ZONE
);
-- Create indexes for better performance
CREATE INDEX IF NOT EXISTS idx_railway_users_email ON railway_users(email);
CREATE INDEX IF NOT EXISTS idx_railway_users_username ON railway_users(username);
CREATE INDEX IF NOT EXISTS idx_railway_users_active ON railway_users(is_active);
-- Create updated_at trigger function
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ language 'plpgsql';
-- Create trigger for updated_at
DROP TRIGGER IF EXISTS update_railway_users_updated_at ON railway_users;
CREATE TRIGGER update_railway_users_updated_at
BEFORE UPDATE ON railway_users
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
-- Insert default test user (for backward compatibility)
INSERT INTO railway_users (email, password_hash, salt, username, full_name, is_active, created_at)
VALUES (
'test@example.com',
'testuser123', -- Special marker for fallback user
'',
'testuser',
'Test User',
true,
'2025-11-04T22:00:00Z'::timestamp
) ON CONFLICT (email) DO NOTHING;