|
| 1 | +.. _tcm_cluster_migrations: |
| 2 | + |
| 3 | +Performing migrations |
| 4 | +===================== |
| 5 | + |
| 6 | +.. include:: index.rst |
| 7 | + :start-after: ee_note_tcm_start |
| 8 | + :end-before: ee_note_tcm_end |
| 9 | + |
| 10 | +|tcm_full_name| provides a web interface for managing and performing migrations |
| 11 | +in connected clusters. To learn more about migrations in Tarantool, see :ref:`migrations`. |
| 12 | + |
| 13 | +Migrations are named Lua files with code that alters the cluster data schema, for example, |
| 14 | +creates a space, changes its format, or adds indexes. In |tcm|, there is a dedicated |
| 15 | +page where you can organize migrations, edit their code, and apply them to the cluster. |
| 16 | + |
| 17 | +.. _tcm_cluster_migrations_manage: |
| 18 | + |
| 19 | +Managing migrations |
| 20 | +------------------- |
| 21 | + |
| 22 | +The tools for managing migrations from |tcm| are located on the **Cluster** > **Migrations** page. |
| 23 | + |
| 24 | +To create a migration: |
| 25 | + |
| 26 | +#. Click **Add** (the **+** icon) on the **Migrations** page. |
| 27 | +#. Enter the migration name. |
| 28 | + |
| 29 | + .. important:: |
| 30 | + |
| 31 | + When naming migrations, remember that they are applied in the lexicographical order. |
| 32 | + Use ordered numbers as filename prefixes to define the migrations order. |
| 33 | + For example, ``001_create_table``, ``002_add_column``, ``003_create_index``. |
| 34 | + |
| 35 | +#. Write the migration code in the editor window. Use the :ref:`box.schema module reference <box_schema>` |
| 36 | + to learn how to work with Tarantool data schema. |
| 37 | + |
| 38 | +Once you complete writing the migration, save it by clicking **Save**. |
| 39 | +This saves the migration that is currently opened in the editor. |
| 40 | + |
| 41 | +.. _tcm_cluster_migrations_apply: |
| 42 | + |
| 43 | +Appliyng migrations |
| 44 | +------------------- |
| 45 | + |
| 46 | +After you prepare a set of migrations, apply it to the cluster. |
| 47 | +To apply all saved migrations to the cluster at once, click **Apply**. |
| 48 | + |
| 49 | +.. important:: |
| 50 | + |
| 51 | + Applying all saved migrations **at once, in the lexicographical order** is the |
| 52 | + only way to apply migrations in |tcm|. There is no way to select a single or |
| 53 | + several migrations to apply. |
| 54 | + The migrations that are already applied are skipped. To learn how to check |
| 55 | + a migration status, see :ref:`tcm_cluster_migrations_check`. |
| 56 | + |
| 57 | +Migrations that were created but not saved yet are not applied when you click **Apply**. |
| 58 | + |
| 59 | +.. _tcm_cluster_migrations_check: |
| 60 | + |
| 61 | +Checking migrations status |
| 62 | +-------------------------- |
| 63 | + |
| 64 | +To check the migration results on the cluster, use the **Migrated** widget on the |
| 65 | +:ref:`cluster stateboard <tcm_ui_cluster_stateboard>`. It reflects the general result |
| 66 | +of the last applied migration set: |
| 67 | + |
| 68 | +- If all saved migration are applied successfully, |
| 69 | + the widget is green. |
| 70 | +- If any migration from this set fails on certain instances, the widget color changes to yellow. |
| 71 | +- If there are saved migrations that are not applied yet, the widget becomes gray. |
| 72 | + |
| 73 | +Hovering a cursor over the widget shows the number of instances on which the currently |
| 74 | +saved migration set is successfully applied. |
| 75 | + |
| 76 | +You can also check the status of each particular migration on the **Migrations** page. |
| 77 | +The migrations that are successfully applied are marked with green check marks. |
| 78 | +Failed migrations are marked with exclamation mark icons (**!**). Hover the cursor over |
| 79 | +the icon to see the information about the error. To reapply a failed migration, |
| 80 | +click **Force apply** in the pop-up with the error information. |
| 81 | + |
| 82 | +.. _tcm_cluster_migrations_example: |
| 83 | + |
| 84 | +Migration file example |
| 85 | +---------------------- |
| 86 | + |
| 87 | +The following migration code creates a formatted space with two indexes in a |
| 88 | +sharded cluster: |
| 89 | + |
| 90 | +.. code-block:: lua |
| 91 | +
|
| 92 | + local function apply_scenario() |
| 93 | + local space = box.schema.space.create('customers') |
| 94 | +
|
| 95 | + space:format { |
| 96 | + { name = 'id', type = 'number' }, |
| 97 | + { name = 'bucket_id', type = 'number' }, |
| 98 | + { name = 'name', type = 'string' }, |
| 99 | + } |
| 100 | +
|
| 101 | + space:create_index('primary', { parts = { 'id' } }) |
| 102 | + space:create_index('bucket_id', { parts = { 'bucket_id' }, unique = false }) |
| 103 | + end |
| 104 | +
|
| 105 | + return { |
| 106 | + apply = { |
| 107 | + scenario = apply_scenario, |
| 108 | + }, |
| 109 | + } |
0 commit comments