ADI-Labs / density

wireless density API
13 stars 26 forks source link

Added postgresql. #17

Closed davidhao3300 closed 9 years ago

davidhao3300 commented 9 years ago

Added user and database creation to bootstrap.sh. Checks if user and database already exists. Resolves #5

natebrennand commented 9 years ago

I think we can make this a bit cleaner by moving the logic to SQL instead of bash scripting.

Something like this seems a bit more maintainable rather than the piping of SQL commands into PG.

--- UNTESTED
DO
$body$
BEGIN
    --- create the user if DNE
    IF NOT EXISTS (
        SELECT *
        FROM   pg_catalog.pg_user
        WHERE  usename = 'adicu'
    ) THEN (
        CREATE ROLE adicu LOGIN PASSWORD 'adicu';
    )
    END IF;

    --- create the database if DNE
    IF NOT EXISTS (
        SELECT *
        FROM   pg_database
        WHERE  datname = 'density'
    ) THEN (
        CREATE DATABASE density WITH
        OWNER adicu
        ENCODING 'UTF-8'
        LC_CTYPE 'en_US.utf8'
        LC_COLLATE 'en_US.utf8'
        TEMPLATE template0;

        CREATE SCHEMA schema;
        ALTER SCHEMA schema OWNER TO adicu;
    )
END
$body$
davidhao3300 commented 9 years ago

Yup, that is cleaner. Main issue I'm dealing with is the fact that you can't create a database within a block statement. Three possibilities here: Drop everything and recreate everything - Prevents error messages, but could drop all our data if the script is run more than once.

Move database creation statement outside of the block - This will cause an error message to appear, but the build will still succeed and we don't lose any data.

Put the database creation logic in the bash script - This makes the bash script look a bit messier, but it removes all error messages.

natebrennand commented 9 years ago

given that this is just for setting up a dev environment it's probably OK if it scraps everything or if it spits out a few error messages

davidhao3300 commented 9 years ago

Okay, sounds good to me. It seems that Slack doesn't notice when someone pushes a commit for an issue. Do we want to include that so reviewers know when to re-check?

natebrennand commented 9 years ago

Slack GH integration doesn't do the new commits, but Travis-CI does listen for them and kicks off a build. Alternative solution is to just tag us / the relevant reviewer in a comment (@adicu/density will give everyone on the project a notification)

natebrennand commented 9 years ago

:+1:

thebrianzeng commented 9 years ago

:+1: