-- Add database_users table to associate users with databases
CREATE TABLE database_users (
    id TEXT PRIMARY KEY,
    uid TEXT NOT NULL,
    db_id TEXT NOT NULL,
    FOREIGN KEY(uid) REFERENCES users(id),
    FOREIGN KEY(db_id) REFERENCES database(id)
);

-- Add index for faster lookups
CREATE INDEX idx_database_users_uid ON database_users(uid);
CREATE INDEX idx_database_users_db_id ON database_users(db_id);
