Skip to content

Instantly share code, notes, and snippets.

@fixNoobi
Last active August 4, 2021 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fixNoobi/04dd8ae3388a7c99c414bd59a570b7f8 to your computer and use it in GitHub Desktop.
Save fixNoobi/04dd8ae3388a7c99c414bd59a570b7f8 to your computer and use it in GitHub Desktop.
Gen SQL from vars

File: init.sql

create database {{pgsql_payment.db}};
create role {{pgsql_payment.user}} with encrypted password '{{pgsql_payment.password}}' LOGIN;

grant all privileges on database {{pgsql_payment.db}} to {{pgsql_payment.user}};
\c {{pgsql_payment.db}}

File: vars.yaml

pgsql_payment:
  user: "user"
  password: "passw)rd"
  db: "bs"

File: req.txt

$ cat > /tmp/requirements.txt <<EOF
Jinja2
pyyaml
j2cli
ruamel.yaml
pika
argparse
EOF

Запускаем.

$ pip3 install -r /tmp/requirements.txt

Устанавливаем нужные нам пакеты для питона.

$ ~/.local/bin/j2 init.sql vars.yaml > /tmp/init.sql

Эта строчка нам гененрирует sql файл на основании vars.yml

$ psql -h HOSTNAME -U USERNAME -f /tmp/init.sql

Эта строка выполняет данные с базой

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment