issue with using liquibase and snowflake db - liquibase

I'm kicking the tires on Snowflake DB and wanted to see how it works with Liquibase. I'm running into an issue when creating the databasechangelog table as Snowflake has a timestamp field but Liquibase is trying to issue SQL with data type of datetime.
I followed the idea on http://www.liquibase.org/databases.html and just created the databasechangelog table outside of liquibase deployment.
CREATE TABLE bruces.DATABASECHANGELOG (ID VARCHAR(255) NOT NULL, AUTHOR VARCHAR(255) NOT NULL, FILENAME VARCHAR(255) NOT NULL, DATEEXECUTED timestamp NOT NULL, ORDEREXECUTED INT NOT NULL, EXECTYPE VARCHAR(10) NOT NULL, MD5SUM VARCHAR(35), DESCRIPTION VARCHAR(255), COMMENTS VARCHAR(255), TAG VARCHAR(255), LIQUIBASE VARCHAR(20), CONTEXTS VARCHAR(255), LABELS VARCHAR(255))
And then I started the liquibase deployment via maven.
WARNING 1/24/17 5:03 PM: liquibase: Unknown database: Snowflake
[INFO] Executing on Database: jdbc:snowflake://*****.snowflakecomputing.com/?db=BRUCE_DB&warehouse=BRUCE_WH
INFO 1/24/17 5:03 PM: liquibase: Successfully acquired change log lock
INFO 1/24/17 5:03 PM: liquibase: Creating database history table with name: bruces.DATABASECHANGELOG
INFO 1/24/17 5:03 PM: liquibase: Successfully released change log lock
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.432 s
[INFO] Finished at: 2017-01-24T17:03:56-06:00
[INFO] Final Memory: 16M/305M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.4.0:update (default) on project snowflake.snowflake_app: Error setting up or running Liquibase: SQL compilation error:
[ERROR] Unsupported data type 'TOK_DATETIME'. [Failed SQL: CREATE TABLE bruces.DATABASECHANGELOG (ID VARCHAR(255) NOT NULL, AUTHOR VARCHAR(255) NOT NULL, FILENAME VARCHAR(255) NOT NULL, DATEEXECUTED datetime NOT NULL, ORDEREXECUTED INT NOT NULL, EXECTYPE VARCHAR(10) NOT NULL, MD5SUM VARCHAR(35), DESCRIPTION VARCHAR(255), COMMENTS VARCHAR(255), TAG VARCHAR(255), LIQUIBASE VARCHAR(20), CONTEXTS VARCHAR(255), LABELS VARCHAR(255))]
[ERROR] -> [Help 1]
It would appear that liquibase can't find the databasechangelog table so it tries to create it and fails.

Not knowing anything at all about SnowflakeDB, I would suggest that the best approach is to write a new database implementation for SnowflakeDB. SQL dialects vary quite a bit, and if you are having issues early, you are likely just going to run into more issues as you move along.

The problem is that today Snowflake does not support the DATETIME data type. It does support DATE and TIMESTAMP, which are standard SQL.
There's an ongoing effort to add it to Snowflake, will ask the team working on it to add updates here.

I see that's added. Snowflake however, converts the data type to TIMESTAMP_NTZ while creating the attribute. Try using the Snowflake extension and creating the table using the XML and provide either TIMESTAMP_NTZ or TIMESTAMP_NTZ(9) or DATETIME. All seems to be the same in Snowflake -

Related

Liquibase unable to execute schema (Snowflake) with mixed case eg. (This_Schema)

I have tried using liquibase tool for our snowflake db. It is all working with where SCHEMA name is in all CAPITAL(UPPERCASE). But liquibase is not picking up any of my schema's with mixed case, eg (This_Schema).
I have tried putting this but didn't help.
<defaultSchemaName>This_Schema</defaultSchemaName>
POM.XML configuration example:
<driver>net.snowflake.client.jdbc.SnowflakeDriver</driver>
<url>jdbc:snowflake://${env.SNOWFLAKE_ACCOUNT}.eu-central-1.snowflakecomputing.com/?db=${env.SNOWFLAKE_DB}&schema=${env.SNOWFLAKE_SCHEMA}&warehouse=${env.SNOWFLAKE_WH}&role=${env.SNOWFLAKE_ROLE}</url>
<username>${env.SNOWFLAKE_USERNAME}</username>
<password>${env.SNOWFLAKE_PASSWORD}</password>
Error setting up or running Liquibase: liquibase.exception.DatabaseException: SQL compilation error:
[ERROR] Schema 'LIQUIBASE_DB.THIS_SCHEMA' does not exist. [Failed SQL: CREATE TABLE THIS_SCHEMA.DATABASECHANGELOGLOCK (ID INT NOT NULL, LOCKED BOOLEAN NOT NULL, LOCKGRANTED TIMESTAMP_NTZ, LOCKEDBY VARCHAR(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))]
NOTE: "This_Schema" is the name of my schema as it is showing here, but upon executing liquibase update this automatically changes to UPPERCASE value as in error above.
Found this comment in the README file from the liquibase snowflake extension.
The Snowflake JDBC drivers implementation of
DatabaseMetadata.getTables() hard codes quotes around the catalog,
schema and table names, resulting in queries of the form:
show tables like 'DATABASECHANGELOG' in schema "sample_db"."sample_schema"
This results in the DATABASECHANGELOG table not being found, even
after it has been created. Since Snowflake stores catalog and schema
names in upper case, the getJdbcCatalogName returns an upper case
value.
Could this explain your problems?...

Wrong executed SQL Statement error

TL;DR: How do I make the table refresh with the new, updated columns?
Hi, I'm getting an error which states that I have invalid column names. The column names which are invalid have been deleted before hand and updated then.
When I refresh the table's data, the error is displayed again stating: SELECT TOP [1000], Error Source: .Net SqlClient Data Provider and the invalid column names.
The error is straight forward, but how do I manage to change the "default" refresh query of the table? I checked the table from SQL Managment Studio and Visual Studio and everything seems right... it's just that this query is not adapting to the update which I done to the table. This table had a foreign key with another table but I'm sure that I deleted any links with other tables.
Just in case this is the code of the table:
CREATE TABLE [dbo].[Receipt] (
[receiptID] INT IDENTITY (1, 1) NOT NULL,
[employeeUser] NVARCHAR (50) NULL,
[purchasedProductID] INT NULL,
[productName] NVARCHAR (50) NULL,
[clientID] INT NULL,
PRIMARY KEY CLUSTERED ([receiptID] ASC)
);
Thanks alot and take care!
SOLVED
Apparently the "Did you try turning it on/off" method work sometimes...
I restarted my visual studio project and worked.

#1146 - Table 'phpmyadmin.pma__tracking' doesn't exist

Having a problem opening any of my databases in phpMyadmin
I tried deleting a lot of old, irrelevant databases and may have in the process
deleted something I shouldn't have and was wondering what I could do to resolve the error
#1146 - Table 'phpmyadmin.pma__tracking' doesn't exist
All the phpMyAdmin tables are defined in the SQL dump that comes with the package in sql/create_tables.sql. You can import that file in it's entirety (will also re-create any other tables you might have dropped) or just create the missing table by running this query:
CREATE TABLE IF NOT EXISTS `pma__tracking` (
`db_name` varchar(64) NOT NULL,
`table_name` varchar(64) NOT NULL,
`version` int(10) unsigned NOT NULL,
`date_created` datetime NOT NULL,
`date_updated` datetime NOT NULL,
`schema_snapshot` text NOT NULL,
`schema_sql` text,
`data_sql` longtext,
`tracking` set('UPDATE','REPLACE','INSERT','DELETE','TRUNCATE','CREATE DATABASE','ALTER DATABASE','DROP DATABASE','CREATE TABLE','ALTER TABLE','RENAME TABLE','DROP TABLE','CREATE INDEX','DROP INDEX','CREATE VIEW','ALTER VIEW','DROP VIEW') default NULL,
`tracking_active` int(1) unsigned NOT NULL default '1',
PRIMARY KEY (`db_name`,`table_name`,`version`)
)
COMMENT='Database changes tracking for phpMyAdmin'
DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
Switch to the phpmyadmin database. You can then use the "SQL" tab to execute this query directly on the database.
I had this problem after installed XAMPP. I did the following:
In /opt/lampp/bin1 use ./mysql_upgrade -u root with option -p if you use a password.
In /opt/lampp/var/mysql/phpmyadmin rm all *.ibd files.
Import create_tables.sql in phpMyAdmin GUI or run it in console.
Had similar problem.
I created pma__ tables in my project db by clicking something in operations tab of that db.
Then I deleted my db, created new with the same name and got "table does not exist" problem.
Fixed it by executing modified sql/create_table.sql on my db. Had to delete phpmyadmin db creation and use from there.
I had this issue when I switched from mysql to maraidb. The solution was to do the following, run the create tables script from the console.
Get to the terminal
$ mysql -uroot -padmin
Then import the create phpmyadmin db and tables script, I got it from Oldskool's answer above. (READ it before running it)
MariaDB [(none)]> source create_tables_phpmyadmin.sql;
Query OK, 1 row affected (0.00 sec)
Database changed
Query OK, 0 rows affected (0.02 sec)
...
In case of exists error you may clear your previous phpmyadmin db that you had tried adding.

Generating Liquibase metadata offline

I'm currently experimenting with Liquibase to generate SQL for our database migrations. Due to some constraints within our environment, we need to generate the SQL "offline" and then have that executed against the target database(s) by a DBA.
I've been able to use updateSQL / rollbackSQL with the Maven plugin to generate the SQL and that seems to work fine.
However, the output does not include any of the metadata information - i.e. there are no creates for the DATABASECHANGELOG table and none of the inserts for that table are included in the generated script.
Is it possible to include the metadata information in the generated SQL?
I'm using Liquibase 3.1.1 (Maven plugin is the same version). I've also tried this from the command line and the behaviour is consistent - i.e. I get the actual changes generated, but not the metadata.
There is not support currently in 3.1.1. It will hopefully be added as a feature in 3.2. https://liquibase.jira.com/browse/CORE-1726.
Are you able to run updateSQL against a backup database that matches production? That will still not execute anything but will include the metadata statements as well. The backup would actually just need the databasechangelog table because that is all liquibase reads unless you are using preconditions.
Running the main method with the option "outputLiquibaseSql=true" as shown here:
liquibase.integration.commandline.Main.main(new String[]{"--changeLogFile=src/test/resources/db.changelog.xml"
,"--outputFile=target/updateSql.txt"
,"--url=offline:unknown?outputLiquibaseSql=true"
, "updateSQL"});
Generates SQL like:
-- *********************************************************************
-- Update Database Script
-- *********************************************************************
-- Change Log: src/test/resources/db.changelog.xml
-- Ran at: 12/04/20 11:51
-- Against: null#offline:unknown?outputLiquibaseSql=true
-- Liquibase version: 3.8.9
-- *********************************************************************
CREATE TABLE DATABASECHANGELOG (ID VARCHAR(255) NOT NULL, AUTHOR VARCHAR(255) NOT NULL, FILENAME VARCHAR(255) NOT NULL, DATEEXECUTED datetime NOT NULL, ORDEREXECUTED INT NOT NULL, EXECTYPE VARCHAR(10) NOT NULL, MD5SUM VARCHAR(35), DESCRIPTION VARCHAR(255), COMMENTS VARCHAR(255), TAG VARCHAR(255), LIQUIBASE VARCHAR(20), CONTEXTS VARCHAR(255), LABELS VARCHAR(255), DEPLOYMENT_ID VARCHAR(10));
-- Changeset src/test/resources/db.changelog.xml::createTable-example::liquibase-docs
CREATE TABLE public.person (address VARCHAR(255));
INSERT INTO DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE, DEPLOYMENT_ID) VALUES ('createTable-example', 'liquibase-docs', 'src/test/resources/db.changelog.xml', CURRENT_TIMESTAMP, 1, '8:49e8eb557129b33d282c4ad2fdc5d4d9', 'createTable tableName=person', '', 'EXECUTED', NULL, NULL, '3.8.9', '6688703163');
As it is running in "offline:unknown" mode it also outputs CSV which are the entries to put into the DATABASECHANGELOG table:
"ID","AUTHOR","FILENAME","DATEEXECUTED","ORDEREXECUTED","EXECTYPE","MD5SUM","DESCRIPTION","COMMENTS","TAG","LIQUIBASE","CONTEXTS","LABELS","DEPLOYMENT_ID"
"createTable-example","liquibase-docs","src/test/resources/db.changelog.xml","2020-04-12T11:51:43.178","2","EXECUTED","8:49e8eb557129b33d282c4ad2fdc5d4d9","createTable tableName=person",,"","3.8.9","()","","6688703163"

DokuWiki and SQL code

I recently installed DokuWiki on my domain and ran in one nasty problem.
I am trying to enter such code:
CREATE TABLE LOOM(
ID INT NOT NULL,
KIIP_ID INT NOT NULL,
NIMI VARCHAR(50) NOT NULL,
SYND DATE NOT NULL,
SURM DATE,
PRIMARY KEY (ID));
between tags and if I am trying to preview or save the change, DokuWiki shows me this:
This topic does not exist yet
You've followed a link to a topic that doesn't exist yet. If permissions allow, you may create it by using the Create this page button.
How to fix this?
See http://www.dokuwiki.org/faq:mod_security
You should escape the commands between the <code></code> tags. Like the below.
<code>
CREATE TABLE LOOM(
ID INT NOT NULL,
KIIP_ID INT NOT NULL,
NIMI VARCHAR(50) NOT NULL,
SYND DATE NOT NULL,
SURM DATE,
PRIMARY KEY (ID));
</code>
If you still have problems previewing then Andreas is right it is most likely a web server configuration issue with Apache. To validate that you could redploy on nginx and see if the issue still persists. I have a tutorial about deploying dokuwiki on nginx here: http://bigthinkingapplied.com/launching-a-private-wikipedia-using-dokuwiki/