27 lines
982 B
SQL
27 lines
982 B
SQL
-- Database initialization script for PostgreSQL
|
|
-- This will be executed when the container starts for the first time
|
|
|
|
-- Create database if it doesn't exist
|
|
CREATE DATABASE IF NOT EXISTS homework;
|
|
|
|
-- Switch to the homework database
|
|
\c homework;
|
|
|
|
-- Create tables (adjust according to your actual schema)
|
|
CREATE TABLE IF NOT EXISTS users (
|
|
id SERIAL PRIMARY KEY,
|
|
email VARCHAR(255) UNIQUE NOT NULL,
|
|
password_hash VARCHAR(255) NOT NULL,
|
|
role VARCHAR(50) NOT NULL DEFAULT 'User',
|
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
-- Create indexes for better performance
|
|
CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);
|
|
|
|
-- Insert sample data (remove in production)
|
|
INSERT INTO users (email, password_hash, role) VALUES
|
|
('admin@example.com', '$2a$11$example.hash.here', 'Admin'),
|
|
('user@example.com', '$2a$11$example.hash.here', 'User')
|
|
ON CONFLICT (email) DO NOTHING; |