Automatically create control table if it doesn't exists

This commit is contained in:
Rikard Bartholf
2016-02-17 15:11:11 +01:00
parent 375c521e17
commit 2c5c2d2034
2 changed files with 11 additions and 11 deletions
+11
View File
@@ -8,6 +8,17 @@ fi
source env/$DB_ENVIRONMENT.conf
# Create the control table, if it doesn't exist
cat <<-EOF | psql $PSQL_OPTS -d $DB_NAME
BEGIN;
CREATE TABLE IF NOT EXISTS database_versions (
version varchar(32) not null,
is_active boolean not null default false,
creation_date timestamp not null default current_timestamp
);
END;
EOF
function add-version() {
psql $PSQL_OPTS -c "update database_versions set is_active = false where is_active = true" $DB_NAME
psql $PSQL_OPTS -c "insert into database_versions (version, is_active) values ('$1', TRUE)" $DB_NAME