Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbeaver/pro#3348 cb database migration #3003

Draft
wants to merge 3 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions config/core/cloudbeaver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
},

database: {
driver: "${CLOUDBEAVER_DB_DRIVER:h2_embedded_v2}",
url: "${CLOUDBEAVER_DB_URL:jdbc:h2:${workspace}/.data/cb.h2v2.dat}",
driver: "${CLOUDBEAVER_DB_DRIVER:sqlite_jdbc}",
url: "${CLOUDBEAVER_DB_URL:jdbc:h2:${workspace}/.data/cb.sqlite.db}",
schema: "${CLOUDBEAVER_DB_SCHEMA:''}",
user: "${CLOUDBEAVER_DB_USER:''}",
password: "${CLOUDBEAVER_DB_PASSWORD:''}",
Expand All @@ -55,7 +55,8 @@
minIdleConnections: "${CLOUDBEAVER_DB_MIN_IDLE_CONNECTIONS:4}",
maxIdleConnections: "${CLOUDBEAVER_DB_MAX_IDLE_CONNECTIONS:10}",
maxConnections: "${CLOUDBEAVER_DB_MAX_CONNECTIONS:100}",
validationQuery: "${CLOUDBEAVER_DB_VALIDATION_QUERY:SELECT 1}"
validationQuery: "${CLOUDBEAVER_DB_VALIDATION_QUERY:SELECT 1}",
bootstrapQuery: "${CLOUDBEAVER_QM_DB_BOOTSTRAP_QUERY:pragma journal_mode=wal}"
},
backupEnabled: "${CLOUDBEAVER_DB_BACKUP_ENABLED:true}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Bundle-ClassPath: .
Require-Bundle: org.jkiss.dbeaver.model;visibility:=reexport,
org.jkiss.dbeaver.model.jdbc,
org.jkiss.dbeaver.model.sql,
org.jkiss.dbeaver.model.sql.jdbc,
org.jkiss.dbeaver.model.sql.jdbc;visibility:=reexport,
org.jkiss.dbeaver.registry;visibility:=reexport,
org.jkiss.bundle.apache.dbcp;visibility:=reexport,
io.cloudbeaver.model
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.cloudbeaver.service.security.db;

import io.cloudbeaver.model.config.WebDatabaseConfig;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.schema.SQLSchemaVersionManager;
import org.jkiss.utils.CommonUtils;

import java.sql.Connection;
import java.sql.SQLException;

public class BaseCBSchemaManager implements SQLSchemaVersionManager {
@NotNull
protected final WebDatabaseConfig databaseConfig;

public BaseCBSchemaManager(@NotNull WebDatabaseConfig databaseConfig) {
this.databaseConfig = databaseConfig;
}

@Override
public int getCurrentSchemaVersion(DBRProgressMonitor monitor, Connection connection, String schemaName)
throws DBException, SQLException {

Check warning on line 40 in server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/BaseCBSchemaManager.java

View workflow job for this annotation

GitHub Actions / Server / Lint

[checkstyle] reported by reviewdog 🐶 'throws' has incorrect indentation level 8, expected level should be 12. Raw Output: /github/workspace/./server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/db/BaseCBSchemaManager.java:40:9: warning: 'throws' has incorrect indentation level 8, expected level should be 12. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
// Check and update schema
try {
int version = CommonUtils.toInt(JDBCUtils.executeQuery(connection,
CommonUtils.normalizeTableNames(
"SELECT VERSION FROM {table_prefix}CB_SCHEMA_INFO",
databaseConfig.getSchema()
)
));
return version == 0 ? 1 : version;
} catch (SQLException e) {
try {
Object legacyVersion = CommonUtils.toInt(JDBCUtils.executeQuery(connection,
CommonUtils.normalizeTableNames(
"SELECT SCHEMA_VERSION FROM {table_prefix}CB_SERVER",
databaseConfig.getSchema())
));
// Table CB_SERVER exist - this is a legacy schema
return CBDatabase.LEGACY_SCHEMA_VERSION;
} catch (SQLException ex) {
// Empty schema. Create it from scratch
return -1;
}
}
}

@Override
public int getLatestSchemaVersion() {
return CBDatabase.CURRENT_SCHEMA_VERSION;
}

@Override
public void updateCurrentSchemaVersion(
DBRProgressMonitor monitor,
@NotNull Connection connection,
@NotNull String schemaName,
int version
) throws DBException, SQLException {
var updateCount = JDBCUtils.executeUpdate(
connection,
CommonUtils.normalizeTableNames(
"UPDATE {table_prefix}CB_SCHEMA_INFO SET VERSION=?,UPDATE_TIME=CURRENT_TIMESTAMP",
databaseConfig.getSchema()
),
version
);
if (updateCount <= 0) {
JDBCUtils.executeSQL(
connection,
CommonUtils.normalizeTableNames(
"INSERT INTO {table_prefix}CB_SCHEMA_INFO (VERSION,UPDATE_TIME) VALUES(?,CURRENT_TIMESTAMP)",
databaseConfig.getSchema()
),
version
);
}
}

}
Loading
Loading