|
| 1 | +/*- |
| 2 | + * ========================LICENSE_START================================= |
| 3 | + * flyway-database-duckdb |
| 4 | + * ======================================================================== |
| 5 | + * Copyright (C) 2010 - 2025 Red Gate Software Ltd |
| 6 | + * ======================================================================== |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * =========================LICENSE_END================================== |
| 19 | + */ |
| 20 | +package org.flywaydb.community.database.duckdb; |
| 21 | + |
| 22 | +import org.flywaydb.core.api.configuration.Configuration; |
| 23 | +import org.flywaydb.core.internal.database.base.Database; |
| 24 | +import org.flywaydb.core.internal.database.base.Table; |
| 25 | +import org.flywaydb.core.internal.jdbc.JdbcConnectionFactory; |
| 26 | +import org.flywaydb.core.internal.jdbc.StatementInterceptor; |
| 27 | + |
| 28 | +public class DuckDBDatabase extends Database<DuckDBConnection> { |
| 29 | + |
| 30 | + public DuckDBDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor) { |
| 31 | + super(configuration, jdbcConnectionFactory, statementInterceptor); |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + protected DuckDBConnection doGetConnection(java.sql.Connection connection) { |
| 36 | + return new DuckDBConnection(this, connection); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public void ensureSupported(Configuration configuration) { |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public boolean supportsDdlTransactions() { |
| 45 | + return true; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public String getBooleanTrue() { |
| 50 | + return "true"; |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public String getBooleanFalse() { |
| 55 | + return "false"; |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public boolean catalogIsSchema() { |
| 60 | + return false; |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public String getRawCreateScript(Table table, boolean baseline) { |
| 65 | + final var createTable = """ |
| 66 | + CREATE TABLE %s ( |
| 67 | + installed_rank INTEGER NOT NULL, |
| 68 | + version VARCHAR, |
| 69 | + description VARCHAR NOT NULL, |
| 70 | + type VARCHAR NOT NULL, |
| 71 | + script VARCHAR NOT NULL, |
| 72 | + checksum INTEGER, |
| 73 | + installed_by VARCHAR NOT NULL, |
| 74 | + installed_on TIMESTAMP NOT NULL DEFAULT now(), |
| 75 | + execution_time INTEGER NOT NULL, |
| 76 | + success BOOLEAN NOT NULL |
| 77 | + ); |
| 78 | + """.formatted(table); |
| 79 | + final var baselineStatement = baseline ? getBaselineStatement(table) + ";\n" : ""; |
| 80 | + |
| 81 | + return createTable + baselineStatement; |
| 82 | + } |
| 83 | +} |
0 commit comments