I have discovered in our Postgres Database there is a unique constraint on a table, which we haven´t created.
Error message:
SqlExceptionHelper - FEHLER: doppelter Schlüsselwert verletzt Unique-Constraint »uconstr_service_out_mapping«
Detail: Schlüssel »(service_id, mapping_id)=(7, 262144)« existiert bereits.
My first thought was, that Hibernate has to generate this constraint automatically. But we disabled the Auto-Generation of the DDL with the following configuration:
<property name="hibernate.hbm2ddl.auto" value=""/>
We are using Liquibase to create the table:
<changeSet author="foo" id="bar">
<createTable tableName="service_in_mapping">
<column name="masterdata_type" type="INT4">
<constraints nullable="false"/>
</column>
<column name="service_id" type="INT8">
<constraints nullable="false"/>
</column>
<column name="service_type" type="VARCHAR(255)">
<constraints nullable="false"/>
</column>
<column name="non_matching" type="VARCHAR(20)"/>
<column name="mapping_id" type="INT8"/>
</createTable>
</changeSet>
How can this unique constraint be constantly created? Any ideas?
Used Dependency Versions:
Hibernate 5.2.8
Postgres Jdbc 9.1-901.jdbc4
Related
When creating a table in XML to be deployed to Redshift database using Liquibase
<createTable schemaName= "staging" tableName="tempauto">
<column name="key" type="integer" autoIncrement="true">
<constraints nullable="false"/>
</column>
ERROR: Column "key" has unsupported type "serial"
I expected the column key to be created as an int like SQL and to auto-increment.
However Liquibase converts the auto-increment column to type 'serial' which is not supported in Redshift.
I'm using liferay 6.2 and I want to add a new table on service.xml.
The new entry on service.xml is:
<entity name="FeedError" local-service="true" remote-service="false" cache-enabled="false">
<column name="feId" type="long" primary="true" id-type="identity" />
<column name="errorCode" type="String" />
<column name="translation" type="String" />
<column name="facility" type="String" />
<column name="recordId" type="long" />
<column name="dateTime" type="Date" />
</entity>
Then, when running Build Service with Ant or Liferay Plugin, I got the following error:
BUILD FAILED
/Liferay/liferay-plugins-sdk-6.2/build-common-plugin.xml:443: The following error occurred while executing this line:
/Liferay/liferay-plugins-sdk-6.2/build-common-plugin.xml:147: Service Builder generated exceptions.
Looking at build-common-plugin.xml:443 is:
439: <build-service
440: service.api.dir="${basedir}/${service.base.dir}/service"
441: service.sql.dir="${basedir}/${service.base.dir}/sql"
442: service.test.dir=""
443: />
The error is only when adding a new entry to service.xml; for existing ones, it builds without any issue.
Any help is great appreciate!
I hardly remember that there was an issue with the keyword "error" in table or column names. The service builder once greped for this keyword. You might give it a try to not use the word "error" in your column definition.
I use liquibase and I want to create enum in my xml file (PostgreSQL).
As an example below changelog file (only a piece of the file) that creates new table:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="r3.3.0_table_creation_research_document "
author="anonim">
<createTable tableName="research_document">
<column name="id" type="bigint">
<constraints primaryKey="true"
primaryKeyName="research_document_pkey" nullable="false" />
</column>
I can't find any info/examples in Internet!
I don't think liquibase supports enum for postgres natively in the xml format. However, since it is possible in postgres, you could always use liquibase's formatted sql instead of xml:
--liquibase formatted sql
--changeset ronak:1
CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
CREATE TABLE person (
name text,
current_mood mood
);
--rollback drop table person;
I've got a postgresql database that is created from liquibase. How can I configure liquibase to create CITEXT columns?
I ran across this URL but unsure where to put this configuration. I'm using version 3.3.2.
https://liquibase.jira.com/browse/CORE-1234
Thanks for any help.
You will need to edit the changelog file. You didn't specify what format your changelog is in, so this assumes XML, but the instructions are similar for other formats.
Basically, if you have a column that should be CITEXT, you can use that type in the XML declaration:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog">
<changeSet author="Pete" id="1430490076262-3216" objectQuotingStrategy="QUOTE_ALL_OBJECTS">
<createTable tableName="AA_BUILD">
<column name="STAGE" type="NUMBER">
<constraints nullable="false"/>
</column>
<column name="ITERATION" type="NUMBER">
<constraints nullable="false"/>
</column>
<column name="BUILD_NUM" type="NUMBER">
<constraints nullable="false"/>
</column>
<column name="CHANGED_IN_DEV_DT" type="date"/>
<column name="DESCRIPTION" type="CITEXT"/>
</createTable>
</changeSet>
I'm using the dropwizard-migrations module for liquibase db refactoring. See the guide here: http://dropwizard.codahale.com/manual/migrations/
When I run
java -jar my_project.jar db migrate my_project.yml
I get the following error:
ERROR [2013-09-11 20:53:43,089] liquibase: Change Set migrations.xml::11::me failed. Error: Error executing SQL CREATE OR REPLACE TRIGGER add_current_date_to_my_table BEFORE UPDATE ON my_table FOR EACH ROW EXECUTE PROCEDURE change_update_time();: ERROR: syntax error at or near "TRIGGER"
Position: 19
Here are some relevant changesets from my migrations.xml file:
<changeSet id="1" author="me">
<createProcedure>
CREATE OR REPLACE FUNCTION change_update_time() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
NEW.updated_at := CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$;
</createProcedure>
<rollback>
DROP FUNCTION change_update_time();
</rollback>
</changeSet>
<changeSet id="2" author="me">
<preConditions>
<not>
<tableExists tableName="my_table"/>
</not>
</preConditions>
<createTable tableName="my_table">
<column name="_id" type="integer" defaultValue="0">
<constraints nullable="false"/>
</column>
<column name="updated_at" type="timestamp without time zone" defaultValue="now()">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
<changeSet id="3" author="me">
<sql splitStatements="false">
CREATE OR REPLACE TRIGGER add_current_date_to_my_table BEFORE UPDATE ON my_table FOR EACH ROW EXECUTE PROCEDURE change_update_time();
</sql>
<rollback>
DROP TRIGGER add_current_date_to_my_table ON my_table;
</rollback>
</changeSet>
Is there any way I can create the trigger add_current_date_to_my_table? Is this redundant with the "RETURNS trigger" from creating the function?
The solution is:
<changeSet id="3" author="me">
<sql>
DROP TRIGGER IF EXISTS add_current_date_to_my_table ON my_table;
CREATE TRIGGER add_current_date_to_my_table BEFORE UPDATE ON my_table FOR EACH ROW EXECUTE PROCEDURE change_update_time();
</sql>
<rollback>
DROP TRIGGER add_current_date_to_my_table ON my_table;
</rollback>
</changeSet>
H/T Jens.
Ann Kilzer has provided the right answer as there is no CREATE OR REPLACE statement in Postgres, unlike PL/SQL.
So we need to split this statement into 2 atomic operations:
DROP TRIGGER
CREATE TRIGGER