Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#4022] improvement(core): Version manange for H2 database (#4054)

lwyang20b9344c8b1e
diff --git a/core/src/main/java/org/apache/gravitino/storage/relational/database/H2Database.java b/core/src/main/java/org/apache/gravitino/storage/relational/database/H2Database.java
index bd3c044360..4214a9baed 100644
--- a/core/src/main/java/org/apache/gravitino/storage/relational/database/H2Database.java
+++ b/core/src/main/java/org/apache/gravitino/storage/relational/database/H2Database.java
@@ -58,7 +58,7 @@ public class H2Database implements JDBCDatabase {
Statement statement = connection.createStatement()) {
String sqlContent =
FileUtils.readFileToString(
- new File(gravitinoHome + "/scripts/h2/schema-h2.sql"), StandardCharsets.UTF_8);
+ new File(gravitinoHome + "/scripts/h2/schema-0.6.0-h2.sql"), StandardCharsets.UTF_8);
statement.execute(sqlContent);
} catch (Exception e) {
diff --git a/core/src/test/java/org/apache/gravitino/storage/relational/TestJDBCBackend.java b/core/src/test/java/org/apache/gravitino/storage/relational/TestJDBCBackend.java
index 205b56ba3d..da32462552 100644
--- a/core/src/test/java/org/apache/gravitino/storage/relational/TestJDBCBackend.java
+++ b/core/src/test/java/org/apache/gravitino/storage/relational/TestJDBCBackend.java
@@ -148,7 +148,7 @@ public class TestJDBCBackend {
private static void prepareJdbcTable() {
// Read the ddl sql to create table
- String scriptPath = "h2/schema-h2.sql";
+ String scriptPath = "h2/schema-0.6.0-h2.sql";
try (SqlSession sqlSession =
SqlSessionFactoryHelper.getInstance().getSqlSessionFactory().openSession(true);
Connection connection = sqlSession.getConnection();
diff --git a/scripts/h2/schema-h2.sql b/core/src/test/resources/h2/schema-h2.sql
similarity index 98%
rename from scripts/h2/schema-h2.sql
rename to core/src/test/resources/h2/schema-h2.sql
index 0ebf91fa39..3ffa848a83 100644
--- a/scripts/h2/schema-h2.sql
+++ b/core/src/test/resources/h2/schema-h2.sql
@@ -168,7 +168,7 @@ CREATE TABLE IF NOT EXISTS `role_meta` (
CREATE TABLE IF NOT EXISTS `role_meta_securable_object` (
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
`role_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'role id',
- `entity_id` BIGINT(20) NOT NULL COMMENT 'securable object entity id',
+ `entity_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'securable object entity id',
`type` VARCHAR(128) NOT NULL COMMENT 'securable object type',
`privilege_names` VARCHAR(256) NOT NULL COMMENT 'securable object privilege names',
`privilege_conditions` VARCHAR(256) NOT NULL COMMENT 'securable object privilege conditions',
@@ -176,7 +176,8 @@ CREATE TABLE IF NOT EXISTS `role_meta_securable_object` (
`last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'securable object last version',
`deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'securable object deleted at',
PRIMARY KEY (`id`),
- KEY `idx_obj_rid` (`role_id`)
+ KEY `idx_obj_rid` (`role_id`),
+ KEY `idx_obj_eid` (`entity_id`)
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS `user_role_rel` (
diff --git a/docs/how-to-upgrade.md b/docs/how-to-upgrade.md
new file mode 100644
index 0000000000..87401f328f
--- /dev/null
+++ b/docs/how-to-upgrade.md
@@ -0,0 +1,111 @@
+---
+title: How to upgrade Apache Gravitino
+slug: /how-to-upgrade
+license: "This software is licensed under the Apache License version 2."
+---
+
+## Introduction
+This document describes how to upgrade the schema of backed
+Gravitino instance from one release version of Gravitino to another
+release version of Gravitino. For example, by following the steps listed
+below it is possible to upgrade a Gravitino 0.6.0 schema to a
+Gravitino 0.7.0 schema. Before attempting this project we
+strongly recommend that you read through all of the steps in this
+document and familiarize yourself with the required tools.
+
+## Upgrade Steps
+
+### Step 1: Shutdown your Gravitino instance
+Shutdown your Gravitino instance and restrict access to the
+Apache Gravitino's database. It is very important that no one else
+accesses or modifies the contents of database while you are
+performing the schema upgrade.
+
+### Step 2: Backup your Gravitino instance
+Create a backup of your database. This will allow
+you to revert any changes made during the upgrade process if
+something goes wrong.
+
+#### MySQL
+
+For MySQL, you can use the following command to backup your database:
+
+```shell
+mysqldump --opt <db_name> > backup.sql
+```
+Note that you may also need to specify a hostname and username
+using the `--host` and `--user` command line switches.
+
+#### H2
+The easiest way of accomplishing this task is
+by creating a copy of the directory containing your database.
+
+### Step 3: Dump your Gravitino database
+Dump your Gravitino database schema to a file
+
+#### MySQL
+You can use the mysqldump utility to dump the database schema to a file:
+
+```shell
+mysqldump --skip-add-drop-table --no-data <db_name> > schema-x.y.z-mysql.sql
+```
+
+#### H2
+For H2, you can use the `Script` tool to dump the database schema to a file:
+
+```shell
+wget https://repo1.maven.org/maven2/com/h2database/h2/1.4.200/h2-1.4.200.jar
+java -cp h2-1.4.200.jar org.h2.tools.Script -url "jdbc:h2:file:<db_file>;DB_CLOSE_DELAY=-1;MODE=MYSQL" -user <user> -password <password> -script backup.sql
+```
+Note that you may need to specify your h2 file path, username and password
+
+
+### Step 4: Determine differences between your schema and the official schema
+The schema upgrade scripts assume that the schema you are upgrading
+closely matches the official schema for your particular version of
+Gravitino. The files in this directory with names like
+`schema-x.y.z-<type>.sql` contain dumps of the official schemas
+corresponding to each of the released versions of Gravitino. You can
+determine differences between your schema and the official schema
+by comparing the contents of the official dump with the schema dump
+you created in the previous step. Some differences are acceptable and will not interfere
+with the upgrade process, but others need to be resolved manually
+or the upgrade scripts will fail to complete.
+
+### Step 5: Apply the upgrade scripts
+You are now ready to run the schema upgrade scripts. If you are
+upgrading from Gravitino 0.6.0 to Gravitino 0.7.0 you need to run the
+`upgrade-0.6.0-to-0.7.0-<type>.sql` script, but if you are upgrading
+from 0.6.0 to 0.8.0 you will need to run the 0.6.0 to 0.7.0 upgrade
+script followed by the 0.7.0 to 0.8.0 upgrade script.
+
+#### MySQL
+Assuming you are upgrading the version of Gravitino server from 0.6.0 to 0.8.0
+
+```shell
+mysql --verbose
+mysql> use <db_name>;
+Database changed
+mysql> source upgrade-0.6.0-to-0.7.0-mysql.sql
+mysql> source upgrade-0.7.0-to-0.8.0-mysql.sql
+```
+#### H2
+For H2, you can use the `RunScript` tool to apply the upgrade script:
+
+```shell
+java -cp h2-1.4.200.jar org.h2.tools.RunScript -url "jdbc:h2:file:<db_file>;DB_CLOSE_DELAY=-1;MODE=MYSQL" -user <user> -password <password> -script upgrade-0.6.0-to-0.7.0-h2.sql
+java -cp h2-1.4.200.jar org.h2.tools.RunScript -url "jdbc:h2:file:<db_file>;DB_CLOSE_DELAY=-1;MODE=MYSQL" -user <user> -password <password> -script upgrade-0.7.0-to-0.8.0-h2.sql
+```
+
+These scripts should run to completion without any errors. If you
+do encounter errors you need to analyze the cause and attempt to
+trace it back to one of the preceding steps.
+
+### Step 6: Verify the upgrade
+The final step of the upgrade process is validating your freshly
+upgraded schema against the official schema for your particular
+version of Gravitino. This is accomplished by repeating steps (3) and
+(4), but this time comparing against the official version of the
+upgraded schema, e.g. if you upgraded the schema to Gravitino 0.8.0 then
+you will want to compare your schema dump against the contents of
+`schema-0.8.0-<type>.sql`
\ No newline at end of file
diff --git a/docs/index.md b/docs/index.md
index 71a48ab3a2..d6c9d9260f 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -149,3 +149,4 @@ Gravitino provides several ways to configure and manage the Gravitino server. Se
a Gravitino release.
* [Publish Docker images](./publish-docker-images.md): a guide to publishing Gravitino Docker images;
also lists the change logs of Gravitino CI Docker images and release images.
+* [How to upgrade Gravitino](./how-to-upgrade.md): a guide to upgrading the schema of Gravitino storage backend from one release version to another.
diff --git a/scripts/h2/schema-0.6.0-h2.sql b/scripts/h2/schema-0.6.0-h2.sql
new file mode 100644
index 0000000000..b2aad0282d
--- /dev/null
+++ b/scripts/h2/schema-0.6.0-h2.sql
@@ -0,0 +1,248 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file--
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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.
+--
+
+CREATE TABLE IF NOT EXISTS `metalake_meta` (
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `metalake_name` VARCHAR(128) NOT NULL COMMENT 'metalake name',
+ `metalake_comment` VARCHAR(256) DEFAULT '' COMMENT 'metalake comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'metalake properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'metalake audit info',
+ `schema_version` MEDIUMTEXT NOT NULL COMMENT 'metalake schema version info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'metalake current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'metalake last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'metalake deleted at',
+ PRIMARY KEY (metalake_id),
+ CONSTRAINT uk_mn_del UNIQUE (metalake_name, deleted_at)
+) ENGINE = InnoDB;
+
+
+CREATE TABLE IF NOT EXISTS `catalog_meta` (
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `catalog_name` VARCHAR(128) NOT NULL COMMENT 'catalog name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `type` VARCHAR(64) NOT NULL COMMENT 'catalog type',
+ `provider` VARCHAR(64) NOT NULL COMMENT 'catalog provider',
+ `catalog_comment` VARCHAR(256) DEFAULT '' COMMENT 'catalog comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'catalog properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'catalog audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'catalog current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'catalog last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'catalog deleted at',
+ PRIMARY KEY (catalog_id),
+ CONSTRAINT uk_mid_cn_del UNIQUE (metalake_id, catalog_name, deleted_at)
+) ENGINE=InnoDB;
+
+
+CREATE TABLE IF NOT EXISTS `schema_meta` (
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `schema_name` VARCHAR(128) NOT NULL COMMENT 'schema name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_comment` VARCHAR(256) DEFAULT '' COMMENT 'schema comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'schema properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'schema audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'schema current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'schema last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'schema deleted at',
+ PRIMARY KEY (schema_id),
+ CONSTRAINT uk_cid_sn_del UNIQUE (catalog_id, schema_name, deleted_at),
+ -- Aliases are used here, and indexes with the same name in H2 can only be created once.
+ KEY idx_smid (metalake_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `table_meta` (
+ `table_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'table id',
+ `table_name` VARCHAR(128) NOT NULL COMMENT 'table name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'table audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'table current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'table last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'table deleted at',
+ PRIMARY KEY (table_id),
+ CONSTRAINT uk_sid_tn_del UNIQUE (schema_id, table_name, deleted_at),
+ -- Aliases are used here, and indexes with the same name in H2 can only be created once.
+ KEY idx_tmid (metalake_id),
+ KEY idx_tcid (catalog_id)
+) ENGINE=InnoDB;
+
+
+CREATE TABLE IF NOT EXISTS `fileset_meta` (
+ `fileset_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'fileset id',
+ `fileset_name` VARCHAR(128) NOT NULL COMMENT 'fileset name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `type` VARCHAR(64) NOT NULL COMMENT 'fileset type',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'fileset audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'fileset current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'fileset last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'fileset deleted at',
+ PRIMARY KEY (fileset_id),
+ CONSTRAINT uk_sid_fn_del UNIQUE (schema_id, fileset_name, deleted_at),
+ -- Aliases are used here, and indexes with the same name in H2 can only be created once.
+ KEY idx_fmid (metalake_id),
+ KEY idx_fcid (catalog_id)
+) ENGINE=InnoDB;
+
+
+CREATE TABLE IF NOT EXISTS `fileset_version_info` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `fileset_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'fileset id',
+ `version` INT UNSIGNED NOT NULL COMMENT 'fileset info version',
+ `fileset_comment` VARCHAR(256) DEFAULT '' COMMENT 'fileset comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'fileset properties',
+ `storage_location` MEDIUMTEXT DEFAULT NULL COMMENT 'fileset storage location',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'fileset deleted at',
+ PRIMARY KEY (id),
+ CONSTRAINT uk_fid_ver_del UNIQUE (fileset_id, version, deleted_at),
+ -- Aliases are used here, and indexes with the same name in H2 can only be created once.
+ KEY idx_fvmid (metalake_id),
+ KEY idx_fvcid (catalog_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `topic_meta` (
+ `topic_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'topic id',
+ `topic_name` VARCHAR(128) NOT NULL COMMENT 'topic name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `catalog_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'catalog id',
+ `schema_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'schema id',
+ `comment` VARCHAR(256) DEFAULT '' COMMENT 'topic comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'topic properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'topic audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'topic current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'topic last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'topic deleted at',
+ PRIMARY KEY (topic_id),
+ CONSTRAINT uk_cid_tn_del UNIQUE (schema_id, topic_name, deleted_at),
+ -- Aliases are used here, and indexes with the same name in H2 can only be created once.
+ KEY idx_tvmid (metalake_id),
+ KEY idx_tvcid (catalog_id)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `user_meta` (
+ `user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'user id',
+ `user_name` VARCHAR(128) NOT NULL COMMENT 'username',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'user audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'user current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'user last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'user deleted at',
+ PRIMARY KEY (`user_id`),
+ CONSTRAINT `uk_mid_us_del` UNIQUE (`metalake_id`, `user_name`, `deleted_at`)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `role_meta` (
+ `role_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'role id',
+ `role_name` VARCHAR(128) NOT NULL COMMENT 'role name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'schema properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'role audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'role current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'role last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'role deleted at',
+ PRIMARY KEY (`role_id`),
+ CONSTRAINT `uk_mid_rn_del` UNIQUE (`metalake_id`, `role_name`, `deleted_at`)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `role_meta_securable_object` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `role_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'role id',
+ `entity_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'securable object entity id',
+ `type` VARCHAR(128) NOT NULL COMMENT 'securable object type',
+ `privilege_names` VARCHAR(256) NOT NULL COMMENT 'securable object privilege names',
+ `privilege_conditions` VARCHAR(256) NOT NULL COMMENT 'securable object privilege conditions',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'securable objectcurrent version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'securable object last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'securable object deleted at',
+ PRIMARY KEY (`id`),
+ KEY `idx_obj_rid` (`role_id`),
+ KEY `idx_obj_eid` (`entity_id`)
+ ) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `user_role_rel` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'user id',
+ `role_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'role id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'relation audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'relation current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'relation last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'relation deleted at',
+ PRIMARY KEY (`id`),
+ CONSTRAINT `uk_ui_ri_del` UNIQUE (`user_id`, `role_id`, `deleted_at`),
+ KEY `idx_rid` (`role_id`)
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `group_meta` (
+ `group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'group id',
+ `group_name` VARCHAR(128) NOT NULL COMMENT 'group name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'group audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'group current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'group last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'group deleted at',
+ PRIMARY KEY (`group_id`),
+ CONSTRAINT `uk_mid_gr_del` UNIQUE (`metalake_id`, `group_name`, `deleted_at`)
+ ) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `group_role_rel` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'group id',
+ `role_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'role id',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'relation audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'relation current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'relation last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'relation deleted at',
+ PRIMARY KEY (`id`),
+ CONSTRAINT `uk_gi_ri_del` UNIQUE (`group_id`, `role_id`, `deleted_at`),
+ KEY `idx_gid` (`group_id`)
+ ) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `tag_meta` (
+ `tag_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'tag id',
+ `tag_name` VARCHAR(128) NOT NULL COMMENT 'tag name',
+ `metalake_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metalake id',
+ `tag_comment` VARCHAR(256) DEFAULT '' COMMENT 'tag comment',
+ `properties` MEDIUMTEXT DEFAULT NULL COMMENT 'tag properties',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'tag audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'tag current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'tag last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'tag deleted at',
+ PRIMARY KEY (`tag_id`),
+ UNIQUE KEY `uk_mn_tn_del` (`metalake_id`, `tag_name`, `deleted_at`)
+ ) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS `tag_relation_meta` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
+ `tag_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'tag id',
+ `metadata_object_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'metadata object id',
+ `metadata_object_type` VARCHAR(64) NOT NULL COMMENT 'metadata object type',
+ `audit_info` MEDIUMTEXT NOT NULL COMMENT 'tag relation audit info',
+ `current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'tag relation current version',
+ `last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'tag relation last version',
+ `deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'tag relation deleted at',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `uk_ti_mi_del` (`tag_id`, `metadata_object_id`, `deleted_at`),
+ KEY `idx_tid` (`tag_id`),
+ KEY `idx_mid` (`metadata_object_id`)
+ ) ENGINE=InnoDB;