This application utilizes a modified implementation of the Blazer gem to provide direct SQL access to specific tables with data scoped to an organizational level. Modifications to the Blazer gem are performed in app/overrides directories per Rails documented practices. The Blazer gem version has been locked at 2.5.0 to ensure these overrides remain dependable.
Use of the Blazer gem requires setup in both the production and development environments.
This setup assumes Heroku hosting. Guidance for setup on other hosting platforms is welcome via pull request. The maintainers will also update this document as the application evolves.
Note: Requires, at least, a Standard-0 Postgres instance in Heroku to allow for the creation of additional roles.
Note: For consistency, each org credential should be named with that organization's ID. Example: org7
- Ensure that the initial set of organizations have been setup in the application. Each entry should be present in the database and should have an entry in the
blazer.yml
file.org1: <<: *main url: <%= ENV["ORG1_DATABASE_URL"] %>
- In Heroku, add a credential named
blazer
. - Attach that credential to the application.
- Set permissions to
Read-only
. - Create a credential named
org1
(assuming an organization with an ID of 1). - Attach that credential to the application.
- Leave the permissions blank. They will be set by the Blazer rake task.
- Repeat steps 5-7 for each organization in the application.
- In Heroku, add the environment variables for the blazer credential and all org credentials. The urls will be available under each credential in the Postgres add-on.
BLAZER_DATABASE_URL: add credential uri here
ORG1_DATABASE_URL: add credential uri here
ORG2_DATABASE_URL: add credential uri here
- Run a backup of the production database
- Run the Blazer rake task:
heroku run SAVE=1 rake blazer:add_database_security
. - Log in as an organization user and confirm reporting is now functioning and scoped.
- Add the organization to the application (database and entry in
blazer.yml
) - In Heroku, add a credential for that organization:
org#{ID}
. - Attach that credential to the application.
- Leave the permissions blank. They will be set by the Blazer rake task.
- Add the environment variable for the new credential using the uri available in the Postgres add-on.
ORG#{ID}_DATABASE_URL: add credential uri here
- Run a backup of the production database
- Run the Blazer rake task:
heroku run SAVE=1 rake blazer:add_database_security
. - Log in as an organization user and confirm reporting is now functioning and scoped.
This process assumes initial setup, migration and seeding of a local postgres database as described in the setup instructions.
- Add the file
config/local_env.yml
(this is covered by the application's .gitignore file) - Add the blazer-related environment variables to the
config/local_env.yml
file. These will vary based on your local setup but the pattern provided below should work for most. Replace "password" with your chosen password. Note: A password must be present in the organization urls.BLAZER_DATABASE_URL: postgres://blazer:password@localhost:5432/abalone_development ORG1_DATABASE_URL: postgres://org1:password@localhost:5432/abalone_development ORG2_DATABASE_URL: postgres://org2:password@localhost:5432/abalone_development
- Ensure that each organization has an entry in the
blazer.yml
file.org1: <<: *main url: <%= ENV["ORG1_DATABASE_URL"] %>
- Restart your server
- Run the Blazer rake task:
SAVE=1 bundle exec rake blazer:add_database_security
- Log in as an organization user and confirm reporting is now functioning and scoped.
- Add the organization to the application (database and entry in
blazer.yml
) - Add a url for the new organization to the
config/local_env.yml
file :ORG#{ID}_DATABASE_URL: postgres://org#{ID}:password@localhost:5432/abalone_development
- Restart your server
- Run the Blazer drop rake task:
SAVE=1 bundle exec rake blazer:drop_database_security
- Run the Blazer add rake task:
SAVE=1 bundle exec rake blazer:add_database_security
- Log in as a user for the new organization and confirm reporting is now functioning and scoped.
- Run manual backup of the database
- Confirm that we have a backup of each SQL query (these will need to be re-entered).
- Reset the database through the Heroku interface
heroku run rails db:migrate --app abalone-staging
heroku run rails db:seed --app abalone-staging
heroku run SAVE=1 bundle exec rake blazer:drop_database_security --app abalone-staging
heroku run SAVE=1 bundle exec rake blazer:add_database_security --app abalone-staging
- Restart the worker dyno
- Re-add any SQL queries into the Blazer interface
- animals
- cohorts
- enclosures
- facilities
- locations
- measurement events
- measurement types
- measurements
- mortality events
- operations