Separate out the "DROP" sql code. In docker, it results an error "cannot drop the currently open database".
This commit is contained in:
parent
a0725fea0b
commit
2ea481e281
5 changed files with 7 additions and 6 deletions
|
|
@ -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;
|
\c card_db;
|
||||||
|
|
||||||
CREATE TABLE settings (
|
CREATE TABLE settings (
|
||||||
|
|
|
||||||
2
create_db_init.sql
Normal file
2
create_db_init.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
DROP DATABASE IF EXISTS card_db;
|
||||||
|
CREATE DATABASE card_db;
|
||||||
2
create_db_user.sql
Normal file
2
create_db_user.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
DROP USER cardapp;
|
||||||
|
CREATE USER cardapp WITH PASSWORD 'database_password';
|
||||||
|
|
@ -12,7 +12,9 @@ echo Continue? "(y or n)"
|
||||||
read x
|
read x
|
||||||
|
|
||||||
if [ "$x" = "y" ]; then
|
if [ "$x" = "y" ]; then
|
||||||
|
psql postgres -f create_db_init.sql
|
||||||
psql postgres -f create_db.sql
|
psql postgres -f create_db.sql
|
||||||
|
psql postgres -f create_db_user.sql
|
||||||
psql postgres -f settings.sql
|
psql postgres -f settings.sql
|
||||||
echo Database created
|
echo Database created
|
||||||
else
|
else
|
||||||
|
|
|
||||||
1
select_db.sql
Normal file
1
select_db.sql
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
SELECT 'CREATE DATABASE card_db' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'card_db');
|
||||||
Loading…
Add table
Add a link
Reference in a new issue