Run SQL script on multiple schemas with Flyway - postgresql

I am migrating the DB using Flyway. I have a SQL script file which need to run on multiple schemas hosted on a single database.
In my SQL file if I mention ${db_schema} as the parameter and supply with different schema names, will that work? Is there any other approaches to handle this scenario?
SET search_path TO ${db_schema};

You should be able to use placeholders in flyway to handle more than one schema. Here's an article that outlines how that works.

Related

Checking consistency of SQL tables schemas in Airflow

I have an Airflow pipeline in which I create some tables in a PostgreSQL database (A). This works fine, as I have the tables schemas that reside in some .sql files, which are used to create the tables in aforementioned database. These definitions were downloaded manually from another database, which is also a PostgreSQL db (B).
I'd like to run a consistency check at the start of the Airflow main DAG to check that the tables schemas (found in .sql files) that I use to recreate them in (A) db, are identical to the ones on (B) db.
Note: I also have definitions for views in my .sql files.
How could I accomplish this? Any examples would also be helpful.

PostgreSQL execute statement on same user - but with different privilidges

I need to run multiple user-defined SQL scripts - some using schema modification privileges, others only data modification privileges.
I can do this by executing them using different users (with adequate privileges), however I need to execute all scripts in single transaction.
Is there a way to specify privileges for single SQL statement on existing connection?
Thank you!

export data from database in liquibase format

is it possible to export data in liquibase format from already exist postgresql database? until today i each time when i run my project in groovy grails i was using bootstrap file where i was generating everything to database. to export schemas i used grails dbm-generate-changelog and works fine. i used configure tutorial from http://grails-plugins.github.io/grails-database-migration/2.0.x/index.html
best regard!!! :-)
You can use a regular SQL Dump from your DB in the liquibase migrations with minor effort:
Create your SQL file and put it under grails-app/migrations. E.g.
grails-app/migrations/2016-03-17-002-activiti-5.19.0.2.mysql.create.engine.sql
Add that file to your changelog.groovy
Add the following preamble to the SQL file
--liquibase formatted sql
Separate your SQL file into sections you want to see as changesets (add at least one at the beginning):
--changeset activiti:5.19.0.2-create-engine
See the docs: http://www.liquibase.org/documentation/sql_format.html

Control where liquibase DATABASECHANGELOG tables are created on Z/Os

I'm testing using liquibase for DB2 on Z/Os. I have created several TEST databases running in their own table space. When I run liquibase, it applies my changes but it creates the DATABASECHANGELOG table in SYSDEFLT storage group.
Is it possible to designate where the databaseChangeLog tables are created? Instead of creating them in the SYSDEFLT storage group we would like to designate a user database for them.
Yes, you can. How you do it depends on how you run liquibase.
From the command line, either pass arguments or set the arguments in a liquibase.properties file.
The properties are liquibase.databaseChangeLogTableName and liquibase.databaseChangeLogLockTableName
If you are using other ways of running Liquibase, it will be similar.

Setting up environment for SQL queries

I know the basic syntax of queries but otherwise I'm a beginner with SQL.
I have an SQL file (.sql) and I downloaded a couple programs (pgadmin and sql workbench).
I have no idea how to get from where I am now to actually writing queries and finding information. How do I set up so I can actually import my SQL file and start writing queries?
pgAdmin is the default GUI for PostgreSQL.
SQL Workbench is a free, DBMS-independent, cross-platform SQL query tool.
Either way, you need to connect to a database to actually run queries. The DBMS can either run on your local machine or you can connect to a remote server - where you need access privileges of course.