Last active
September 8, 2019 19:09
-
-
Save mikeananev/2c0896ab9f3b018dd33097790e564d48 to your computer and use it in GitHub Desktop.
migratus postgres example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn run-once-init-db! | |
"# create db and users. | |
this fn should be run once from init stage of migratus. | |
* Params: no params. | |
* Warning: verita.config must be already started. | |
* Returns: | |
Return result of migratus/init." | |
[] | |
(let [{:keys [host port login password db-name]} (-> c/*config* :db-init) | |
migratus-config {:store :database | |
:migration-dir "migrations" | |
:init-script "init.sql" | |
:init-in-transaction? false | |
:db {:subprotocol "postgresql" | |
:subname (str "//" host ":" port "/") | |
:user login | |
:password password}} | |
result (migratus/init migratus-config)] | |
result)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- :disable-transaction | |
-- пользователь который имеет права на модификацию схемы, создание таблиц | |
CREATE USER verita_admin WITH PASSWORD 'pwd'; | |
--;; | |
-- пользователь, под которым соединяются с БД приложения | |
CREATE USER verita_app WITH PASSWORD 'pwd'; | |
--;; | |
CREATE DATABASE veritadb OWNER verita_admin; | |
--;; | |
-- создаем схему verita с владельцем verita_admin | |
CREATE SCHEMA verita AUTHORIZATION verita_admin; | |
--;; | |
GRANT ALL PRIVILEGES ON DATABASE veritadb TO verita_admin; | |
--;; | |
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA verita TO verita_app; | |
--;; | |
-- раздача прав обычному пользователю | |
GRANT CONNECT ON DATABASE veritadb TO verita_app; | |
-- --;; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment