|
#!/bin/bash |
|
|
|
|
|
export POSTGRES_DB=my_database |
|
export POSTGRES_USER=my_username |
|
export POSTGRES_PASSWORD=my_password |
|
|
|
|
|
su - postgres -c "psql -c \"CREATE DATABASE $POSTGRES_DB;\"" |
|
su - postgres -c "psql -c \"CREATE USER $POSTGRES_USER WITH PASSWORD '$POSTGRES_PASSWORD';\"" |
|
su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_DB TO $POSTGRES_USER;\"" |
|
|
|
|
|
su - postgres -c "psql -d $POSTGRES_DB -c \" |
|
CREATE TABLE users ( |
|
id SERIAL PRIMARY KEY, |
|
name VARCHAR(50) NOT NULL, |
|
email VARCHAR(50) UNIQUE NOT NULL |
|
); |
|
INSERT INTO users (name, email) VALUES |
|
('John Doe', '[email protected]'), |
|
('Jane Smith', '[email protected]'); |
|
\"" |
|
|
|
|
|
exec postgres |
|
|