DASSL / ClassDB

An open-source system to let students experiment with relational data
https://dassl.github.io/ClassDB/
Other
8 stars 2 forks source link

No easy way to create a ClassDB database (M) #50

Closed smurthys closed 6 years ago

smurthys commented 7 years ago

I propose a createClassDB.sql to create a DB with the role ClassDB as owner. This script should be run after running prepareClassServer.sql but before running prepareClassDB.sql.

Parameterizing the script to accept a database name probably fixes psql as the client, but it can be instructive to consult the docs for the createdb program.

smurthys commented 7 years ago

All tasks except creating a database are now accomplished in initializedDB.sql in v1.0.

A possible solution is to build on the .psql batch script developed in #99.

wildtayne commented 6 years ago

I agree that prepareDB.psql is the right place to do database creation. One possible approach is to have the user supply a desired database name prior to running prepareDB.psql. This can be accomplished using psql's script variables.

The user would set the value of a script variable (in this example, DB_NAME) by either invoking the -v switch when starting psql (-v DB_NAME=<databaseName>), or running the meta-command \set (\set DB_NAME <databaseName>) once inside psql.

Then, the following code added to the beginning of prepareDB.psql will create a new database with the name stored in DB_NAME, and then connect to it prior to running the ClassDB preparation scripts.

CREATE DATABASE :DB_NAME WITH OWNER = classDB;
\connect :DB_NAME

I did a quick test of this code, and it appears to work. If we do use this method, it will be necessary to add the CREATEDB assertion to prepareDB.psql, as mentioned in the first comment.

smurthys commented 6 years ago

I like the approach to using the -v psql switch. However, I highly recommend using the variable name NEW_DB_NAME, because DB_NAME is too close to the psql variable DBNAME.

After much thinking and research, I have identified two alternative approaches: a simple alternative and a rigorous alternative. I recommend taking the simple alternative for M2. Also, because the existing solution does everything except create the database, this issue gets low priority in the interest of time: it should be addressed only if no other issues of higher priority exist.

The simple alternative is to create a createAndPrepareDB.psql which blindly creates the new database, switches connection, and invokes the existing prepareDB.psql. Any error in creating the new DB and connecting to it will just stop the script. The most likely error is that the specified DB already exists.

The rigorous alternative takes the following approach:

Here are some considerations:

smurthys commented 6 years ago

Removing from M2 due to time constraint.

smurthys commented 6 years ago

I am closing this issue because creating a database simply requires executing the CREATE DATABASE and the installation scripts in ClassDB 2.0 make it extremely easy to add ClassDB to any database.