I'm using Liquibase for my project and would like to rename my changelog files.
From old structure:
databaseChangeLog:
- include:
file: db/changelog/add_pokemons.sql
- include:
file: db/changelog/add_minions.sql
To new structure:
databaseChangeLog:
- include:
file: db/changelog/v001__add_table_pokemons.sql
- include:
file: db/changelog/v002__add_table_minions.sql
The Liquibase documentation unfortunately does not state best practices for such intention.
I was thinking about duplicating my files so I have the old ones plus new ones in one directory and then write a migration to change column filename in the databasechangelog table.
What would be the best approach in your opinion?
The problem here is that liquibase holds the name of file inside databasechangelog.filename. So if you are not using logicalFilePath yet maybe you have a chance.
If those files you've posted are formatted sql files then you could do something like this (example for file db/changelog/add_pokemons.sql):
--liquibase formatted sql logicalFilePath:db/changelog/add_pokemons.sql
and you can rename the actual file to whatever you want.
In that case nothing should be broken inside existing databasechangelog table.
Other than that there is probably no available change that will do that automatically from liquibase.
Related
Could you please help me with this issue?
Encountered an error:
Compilation Error in model metrics_model (models\example\metrics_model.sql)
Model 'model.test_project.metrics_model' (models\example\metrics_model.sql) depends on a source named 'automate.metrics' which was not found
I am having this monotonous error, which I have not been able to solve.
Many thanks beforehand!
This is due to the automate.metrics table missing from the database (either the dbt project’s target database or a different database on the same server). There should be a source.yml or automate.yml file somewhere in your project that defines the source. FYI automate is the schema name and metrics is the table name.
If the source yml file specifies a database for the automate schema, query that database to make sure that the metrics table exists in the automate schema.
If the source yml file doesn’t list a database, then that schema / table should exist in the dbt project’s target database. You can see what the target database is by looking at the profile for your project setup in ~/.dbt/profiles.yml.
For PostgreSQL database please check if the sources.yml file is defined as follows:
version: 2
sources:
- name: name_of the source
schema: name_of_the_schema
quoting:
database: false
schema: false
identifier: false
loader: stitch
tables:
- name: name_of_table1
- name: name_of_table2
Are you seeing this in your dev environment? It's possible that you've not run dbt run after creating the automate.metrics which is preventing metrics_model from referencing it.
Check whether you put source config in the right yaml file. I encountered this issue and tried every solutions including above one. Then finally I forgot to put suffix .yml in the source file, and when dbt can't locate source config in that file.
I use liquibase for migrations and have sql files with cyrillic comments, like example.sql:
--liquibase formatted sql
--changeset user:id1
create table example
(
id varchar(100) primary key
);
-- cyryllic comment here
comment on table kafka_cluster is 'Коммментарий к таблице.';
My changelog is yaml file like:
databaseChangeLog:
- include:
# comment
file: db/changelog/1.0.0/schema/example.sql
When i run application on different OS(my mac and on the linux server) i always got different checksums for same files.
Liquibase version:
compile "org.liquibase:liquibase-core:4.3.1"
I don't know why it happens, files are the same. All files are in the UTF-8 charset.
One of the answers for my question is to have all files in UTF-8 with BOM.
But it's not good for me - make sure that all sql files are with BOM.
Another solution is to move from yaml to xml.
Maybe there is a simpler solution?
Thanx.
I have a question regarding Flyway and managing multiple schemas. I have multiple schemas (schema1, schema2, schema3) with different deployment schedules and different folder locations (sql/schema1, sql/schema2, sql/schema3) with different code.
I want to Flyway to create the schemas before the code deployment but how do I set this up in a single config file? I read the Flyway doc (https://flywaydb.org/documentation/faq#multiple-schemas) but is the example using a single config file? or do i need to create multiple config files (one per schema)?
Can i achieve the same setting comma delimited schema list? will "Schema1" only look in the "sql/Schema1" location? I really dont want Schema1 pulling code from a different folder i.e. sql/Schema2, etc.
Thanks in advance!
When using Flyway with multiple schemas, you need to explicitly say in the sql statements which schema the sql is going to change. You can do this by putting an ALTER SESSION SET CURRENT_SCHEMA=schema1 at the top of each migration file, or prefixing all your statements like CREATE TABLE schema1.bananas.
If this is not practical, it would be best to create a number of config files, each with a single schema specified, and a single location specified. e.g.
flyway.schemas=schema1
flyway.locations=filesystem:sql/schema1
Then you can run Flyway with each config file individually to migrate that particular schema.
I want Liquibase, to generate a changelog, from this DB 'testing'. Is it possible?
I have an existing database already, with its tables and data inside.
jdbc:mysql://localhost:3306/testing
Now, I want Liquibase, to generate a changelog, from this DB 'testing'. Is it possible?
This is my command, but it doesn't work.
liquibase --driver=com.mysql.jdbc.Driver --classpath=C:\mysql-connector-java-5.1.47.jar
--changeLogFile=C:\db.changelog.xml --url="jdbc:mysql://localhost:3306/testing"
--username=root generateChangeLog
I don't use any password.
The error is related to --changeLogFile=C:\db.changelog.xml
I thought, Liquibase will refer to my DB 'testing', and generate changelog, with name 'db.changelog.xml' in folder C.
Which part I'm wrong? Do I miss something?
Or maybe, Liquibase is not intended, to generate changelog, from existing DB?
Or maybe, Liquibase is intended, to generate DB, from changelog only? And not vice versa?
This is possible. You might be having trouble since you are writing to a file in the root of your c: drive. Try c:\temp\changelog instead.
My experience is that liquibase works in increments. So if you run that command on your database, it will produce a file as if everything in the database has to be created in the changelog file (as if starting with a completely empty database).
If you read the text on Liquibase's site regarding this command, it says:
When starting to use Liquibase on an existing database, it is often useful, particularly for testing, to have a way to generate the change log to create the current database schema.
This means that if you:
Execute this command once against your dev database
Run the result against a new database (let's say test)
Run it again on your dev database
Run that file against your test database
You will get a load of errors stating that functions already exist.
I gather that the idea behind this is that you create new entries in the changelog files and executing them against ALL your databases, instead of using other tools and using liquibase for the delta.
Sample entry
<changeSet author="liquibase-docs" id="addColumn-example">
<addColumn catalogName="cat" schemaName="public" tableName="YY">
<column name="xx" type="varchar(255)"/>
</addColumn>
</changeSet>
SQL equivalent
ALTER TABLE yy ADD COLUMN xx INT
This is my 2nd day using Liquibase.
I have a 'backup' or 'Repositry' with the database that I need to create locally on my PC.
I have looked at the documentation, but Im realy not 100% clear on how to run it.
Ive updated the Liquibase.properties file to reflect the correct paths and username and passwords.
How do you run the update command to generate the tables and test data.
Windows 7
The Liquibase documentation on 'Adding Liquibase to an existing project' is probably the best place to start. Basically, you want to set the properties file so that it refers to the existing 'backup' database, and then run liquibase generateChangeLog
This will connect to the existing database and generate a file that contains the structure of the existing database expressed (typically) in an XML file called a changelog. You then create a new properies file that will connect to your local database and use liquibase update to apply the changelog to the local database and populate the structure. Note that this does not typically transfer the data from the existing database to the new database, just the structure - the tables, keys, indexes, etc. If you want to have test data as well, you can either export that data from the existing database, or you might look into crafting the changesets manually. To export the data, a command like this would be used:
java -jar liquibase.jar --changeLogFile="./data/<insert file name> " --diffTypes="data" generateChangeLog