#
# 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.
#

Kyuubi MetaStore Upgrade HowTo
============================

This document describes how to upgrade the schema of a MySQL backed
Kyuubi MetaStore instance from one release version of Kyuubi to another
release version of Kyuubi. For example, by following the steps listed
below it is possible to upgrade a Kyuubi 1.6.0 MetaStore schema to a
Kyuubi 1.7.0 MetaStore 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.

MetaStore Upgrade Steps
=======================

1) Shutdown your MetaStore instance and restrict access to the
   MetaStore's MySQL database. It is very important that no one else
   accesses or modifies the contents of database while you are
   performing the schema upgrade.

2) Create a backup of your MySQL metastore database. This will allow
   you to revert any changes made during the upgrade process if
   something goes wrong. The mysqldump utility is the easiest way to
   create a backup of a MySQL database:

   % mysqldump --opt <metastore_db_name> > metastore_backup.sql

   Note that you may need also need to specify a hostname and username
   using the --host and --user command line switches.

3) Dump your metastore database schema to a file. We use the mysqldump
   utility again, but this time with a command line option that
   specifies we are only interested in dumping the DDL statements
   required to create the schema:

   % mysqldump --skip-add-drop-table --no-data <metastore_db_name> > my-schema-x.y.z.mysql.sql

4) The schema upgrade scripts assume that the schema you are upgrading
   closely matches the official schema for your particular version of
   Kyuubi. The files in this directory with names like
   "metadata-store-schema-x.y.z.mysql.sql" contain dumps of the official schemas
   corresponding to each of the released versions of Kyuubi. You can
   determine differences between your schema and the official schema
   by diffing 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.

5) You are now ready to run the schema upgrade scripts. If you are
   upgrading from Kyuubi 1.6.0 to Kyuubi 1.7.0 you need to run the
   upgrade-1.6.0-to-1.7.0.mysql.sql script, but if you are upgrading
   from 1.6.0 to 1.8.0 you will need to run the 1.6.0 to 1.7.0 upgrade
   script followed by the 1.7.0 to 1.8.0 upgrade script.

   % mysql --verbose
   mysql> use <metastore_db_name>;
   Database changed
   mysql> source upgrade-1.6.0-to-1.7.0.mysql.sql
   mysql> source upgrade-1.7.0-to-1.8.0.mysql.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.

6) The final step of the upgrade process is validating your freshly
   upgraded schema against the official schema for your particular
   version of Kyuubi. 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 Kyuubi 1.7.0 then
   you will want to compare your schema dump against the contents of
   metadata-store-schema-1.7.0.mysql.sql
