diff --git a/create_db.sql b/create_db.sql index 7bc9842..f50285b 100644 --- a/create_db.sql +++ b/create_db.sql @@ -1,9 +1,3 @@ -DROP DATABASE IF EXISTS card_db; -CREATE DATABASE card_db; - -DROP USER IF EXISTS cardapp; -CREATE USER cardapp WITH PASSWORD 'database_password'; - \c card_db; CREATE TABLE settings ( diff --git a/create_db_init.sql b/create_db_init.sql new file mode 100644 index 0000000..2a65afb --- /dev/null +++ b/create_db_init.sql @@ -0,0 +1,2 @@ +DROP DATABASE IF EXISTS card_db; +CREATE DATABASE card_db; diff --git a/create_db_user.sql b/create_db_user.sql new file mode 100644 index 0000000..678c8b1 --- /dev/null +++ b/create_db_user.sql @@ -0,0 +1,2 @@ +DROP USER cardapp; +CREATE USER cardapp WITH PASSWORD 'database_password'; \ No newline at end of file diff --git a/s_create_db b/s_create_db index bf7f18c..f5d85f6 100755 --- a/s_create_db +++ b/s_create_db @@ -12,7 +12,9 @@ echo Continue? "(y or n)" read x if [ "$x" = "y" ]; then + psql postgres -f create_db_init.sql psql postgres -f create_db.sql + psql postgres -f create_db_user.sql psql postgres -f settings.sql echo Database created else diff --git a/select_db.sql b/select_db.sql new file mode 100644 index 0000000..340c842 --- /dev/null +++ b/select_db.sql @@ -0,0 +1 @@ +SELECT 'CREATE DATABASE card_db' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'card_db'); \ No newline at end of file