While trying to generate database using liquibase changelog in Postgres, I am getting following error:
forIndexName is not allowed on postgresql
Following is my change log which is generating same error:
<changeSet author="chintan.patel" id="CP0001">
<createIndex indexName="PK_USER" tableName="USER" unique="true">
<column name="FIRSTNAME"/>
<column name="MIDDLENAME"/>
<column name="LASTNAME"/>
</createIndex>
<addPrimaryKey columnNames="FIRSTNAME, MIDDLENAME, LASTNAME" constraintName="PK_USER" forIndexName="PK_USER" tableName="USER"/>
</changeSet>
This same change set works fine in Oracle.
Please suggest me, whats wrong here.
Related
How to specify schema name within xml databaseChangeLog? E.g. I have created a new schema with the following changelog, after which I want to select newly created schema to populate changes.
<databaseChangeLog>
<changeSet author="quickstart-1" id="quickstart-1">
<sql>
CREATE SCHEMA IF NOT EXISTS schema_name AUTHORIZATION schema_name_user;
</sql>
</changeSet>
</databaseChangeLog>
When I execute rollback from command line it shows successfully executed. But on database there are no changes applied. I am using PostgreSQL DB. The command I used for rollback is
java -jar C:\Users\Ranjith.s\.m2\repository\org\liquibase\liquibase-core\3.5.5\liquibase-core-3.5.5.jar --changeLogFile=src\main\resources\db\changelog\db.changelog-master.xml --url=jdbc:postgresql://localhost/transformation_as_a_service --classpath=C:\softwares\liquibase\lib\postgresql-42.2.11.jar --username=transformation_as_a_service_admin --password=transformation_as_a_service_admin --logLevel=debug rollback version_2020.3.002
I am pasting changelog file for reference
<changeSet id="2020-03-UPDATE-PRIMARY-KEY-TO-COLUMN-PID" author="TAAS">
<preConditions onFail="HALT">
<columnExists tableName="TB_TRANSFORMATION" columnName="PID"/>
</preConditions>
<dropPrimaryKey constraintName="pk_tb_transformation" tableName="TB_TRANSFORMATION"/>
<addUniqueConstraint tableName="TB_TRANSFORMATION" columnNames="ID" constraintName="idx_taas_id" />
<addPrimaryKey tableName="TB_TRANSFORMATION" columnNames="PID" constraintName="idx_taas_pid"/>
<rollback>
<dropPrimaryKey tableName="TB_TRANSFORMATION"/>
<dropColumn tableName="TB_TRANSFORMATION" columnName="PID"/>
<addPrimaryKey tableName="TB_TRANSFORMATION" columnNames="ID" constraintName="idx_taas_id"/>
</rollback>
</changeSet>
<changeSet author="TAAS" id="tag_version_2020.3.002">
<tagDatabase tag="version_2020.3.002" />
</changeSet>
If that is your complete changelog, and you ran liquibase update before running the liquibase rollback command, then it is working as designed. The idea is that you would run update and it would deploy those changes. You then continue on, adding more changesets and deploying them using the update command. But on one of those deployments, you discover a problem and decide that you need to go back to a know good version, so you use the rollback command with the tag, and it rolls back everything AFTER the tag.
I'm trying to create a database in PostgreSQL using Wix ToolSet, but I'm always getting the error "Error -2147467259: failed to create SQL database: pontow, error detail: unknown error." when I try to create a database or the error "Failed to connect to SQL database. (-2147467259 pontow )" when I simple try to execute a to a existing database. I made some research and it seems to be something with access denied, but can't get it working.
I've already tried:
Change 'postgresql.conf' and set 'listen_address = '*'';
Change 'pg_hba.conf' and add the line 'host all all 0.0.0.0/0 trust';
PostgreSQL v9.6 and v11.2;
Give full permissions to "Everyone" to the PosgreSQL folder and subfolders;
Use Wix 'sql:SqlDatabase' SQL Authentication and Windows Authentication;
I'm using Windows 10 x64, Wix ToolSet v3.11.
My Product.wsx file:
<Binary Id="CreateTable" SourceFile=".\CreateTable.sql"/>
<Property Id="SQLUSERNAME" Secure="yes">postgres</Property>
<Property Id="SQLPASSWORD" Secure="yes">test</Property>
<Property Id="SQLSERVER" Secure="yes">localhost</Property>
<Property Id="SQLSERVERPORT" Secure="yes">5432</Property>
<Property Id="DATABASE_NAME" Secure="yes">pontow</Property>
<util:User Id="SQLUser" Name="[SQLUSERNAME]" Password="[SQLPASSWORD]" />
<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id='ProgramFilesFolder' Name='PFiles'>
<Directory Id='InstallDir' Name='Test'>
<Component Id="SqlComponent" Guid="35e0e97e-cdce-428b-b553-d82fadf56b28" KeyPath="yes">
<sql:SqlDatabase Id="SqlDatabase" Database="[DATABASE_NAME]" User="SQLUser"
Server="[SQLSERVER],[SQLSERVERPORT]" CreateOnInstall="yes" DropOnUninstall="yes" ContinueOnError="no">
<sql:SqlScript Id="CreateTable" BinaryKey="CreateTable" ContinueOnError="no" ExecuteOnInstall="yes"/>
</sql:SqlDatabase>
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id='SqlFeature' Title='SqlFeature' Level='1'>
<ComponentRef Id='SqlComponent' />
</Feature>
I expect to create a PosgreSQL database using Wix Toolset or any suggestions to create a database from the Setup.exe would be appreciated.
WixSqlExtension supports SQL Server only, not PostgreSQL.
Index:
CREATE INDEX guild_name_lower_ops
ON guilds
USING btree
(lower(name::text) COLLATE pg_catalog."default" varchar_pattern_ops);
Generated changeset:
<changeSet author="Vlad (generated)" id="1450262497286-89">
<createIndex indexName="guild_name_lower_ops" tableName="guilds" />
</changeSet>
And it doesn't pass "status" command check with "columns is empty" error message.
Why it's not exported? Are there any workarounds so I can still use liquibase with my db?
Liquibase does not currently figure this out for Postgres. The workaround is to alter the XML after it is generated so that when creating new databases, the indexes are created properly.
I'm trying to use liquibase to track changes to a postgresql database using dropwizard-migrations. I'd like to be able to run the migration on the existing production database instead of rebuilding from scratch. Right now I'm testing in staging. I've created a changeset with a precondition.
<changeSet id="3" author="me">
<preConditions onFail="CONTINUE">
<not>
<sequenceExists sequenceName="emails_id_seq"/>
</not>
</preConditions>
<createSequence sequenceName="emails_id_seq" startValue="1" incrementBy="1" />
</changeSet>
My goal is to skip applying the changeset if the sequence is already there. Seems straightforward, but it's not working.
ERROR [2013-09-13 22:19:22,564] liquibase: Change Set migrations.xml::3::me failed. Error: Error executing SQL CREATE SEQUENCE emails_id_seq START WITH 1 INCREMENT BY 1: ERROR: relation "emails_id_seq" already exists
! liquibase.exception.DatabaseException: Error executing SQL CREATE SEQUENCE emails_id_seq START WITH 1 INCREMENT BY 1: ERROR: relation "emails_id_seq" already exists
I've tried using the MARK_RAN instead of CONTINUE too. No luck with that.
A much simpler way to apply your changesets to an existing database, without execution, is to use the changelogSync command.
The following commands demonstrate how to extract a changelog and then sync it with the current database:
liquibase --changeLogFile=mydb.xml generateChangeLog
liquibase --changeLogFile=mydb.xml changelogSync
What the sync command does is create all the entries in the changelog table, so that the liquibase file can now be used as normal to update the database:
liquibase --changeLogFile=mydb.xml update
I solved this problem using the sqlCheck instruction :
<changeSet id="sys-0" context="structural">
<preConditions onFail="MARK_RAN"><sqlCheck expectedResult="0">SELECT count(c.relname) FROM pg_class c WHERE c.relkind = 'S' and c.relname = 'hibernate_sequence'</sqlCheck></preConditions>
<!-- <preConditions><not><sequenceExists schemaName="public" sequenceName="hibernate_sequence"/></not></preConditions> -->
<createSequence schemaName="public" sequenceName="hibernate_sequence"/>
</changeSet>
(tested on liquibase 2.0.1 version)
I did the same that you want to do with a view, and for me it works:
Maybe gives you some idea:
<changeSet author="e-ballo" id="DropViewsAndcreateSynonyms" context="dev,int,uat,prod">
<preConditions onFail="CONTINUE" >
<viewExists viewName="PMV_PACKAGE_ITEMS" schemaName="ZON"/>
<viewExists viewName="PMV_SUBSPLAN_INSTALLTYPES" schemaName="ZON"/>
</preConditions>
<dropView schemaName="ZON" viewName="PMV_PACKAGE_ITEMS" />
<dropView schemaName="ZON" viewName="PMV_SUBSPLAN_INSTALLTYPES" />
<sqlFile path="environment-synonyms.sql" relativeToChangelogFile="true" splitStatements="true" stripComments="true"/>
</changeSet>
I hope it helps
I solved this by running the dropwizard-migrations "fast-forward" command as follows:
java -jar hello-world.jar db fast-forward helloworld.yml
This will mark the next changeset as applied without actually applying it. You may have to do this one time per changeset you want to fast-forward. There is also an --all flag if you want to fast forward everything.
More details can be found here: http://dropwizard.codahale.com/manual/migrations/
Also Remember to check they was no caches, for me I have working with OpenMRS modules but due to caches in openMRS my pre-conditions never got in effects and this causes me to think that my codes are failing instead they never got executed