---
id: import
slug: /versioned/import
title: Migration Directory Import
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

Atlas supports the generation of [custom migration file formats](/versioned/diff#generate-migrations-with-custom-formats)
for a variety of existing migration management tools, e.g. [Flyway](https://flywaydb.org/) or
[golang-migrate/migrate](https://github.com/golang-migrate/migrate). But Atlas has its own format as well and provides
a convenient command to import existing migration directories of supported tools into the Atlas format.

### Flags
When using `atlas migrate import` to import a migration directory, users must supply multiple parameters:
* `--from` the [URL](/concepts/url) to the migration directory to import, the `format` query parameter controls the
migration directory format, e.g. `file://migrations?format=flyway`. Supported formats are `atlas` (default),
`golang-migrate`, `goose`, `flyway`, `liquibase` and `dbmate`.
* `--to` the URL of the migration directory to save imported migration files into, by default it is `file://migrations`.

### Limitations

Importing an existing migration directory has some limitations:

#### Comments not directly preceding a SQL statement will get lost.

<Tabs
defaultValue="source"
values={[
{label: 'source.sql', value: 'source'},
{label: 'imported.sql', value: 'target'},
]}>
<TabItem value="source">

```sql
-- This comment will get lost

-- This will be preserved
/*
    This will be preserved as well
/*
CREATE TABLE `users` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT,
    `age` bigint(20) NOT NULL,
    `name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `age` (`age`)
); -- This will get lost.
```

</TabItem>
<TabItem value="target">

```sql
-- This will be preserved
/*
    This will be preserved as well
/*
CREATE TABLE `users` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT,
    `age` bigint(20) NOT NULL,
    `name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `age` (`age`)
);
```

</TabItem>
</Tabs>

#### Rollback migrations will not get imported.

Atlas does not have the concept of rollback migrations. Therefore migrations to undo an applied migration, often called
"down" or "undo" migrations, will not be imported into the new migration directory. For migration formats having the rollback
migration part of one file separated by some directive, the rollback parts are stripped away.

<Tabs
defaultValue="source"
values={[
{label: 'source.sql', value: 'source'},
{label: 'imported.sql', value: 'target'},
]}>
<TabItem value="source">

```sql
-- +goose Up
CREATE TABLE `users` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT,
    `age` bigint(20) NOT NULL,
    `name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `age` (`age`)
);

-- +goose Down
DROP TABLE `users`;
```

</TabItem>
<TabItem value="target">

```sql
CREATE TABLE `users` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT,
    `age` bigint(20) NOT NULL,
    `name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `age` (`age`)
);
```

</TabItem>
</Tabs>

#### Repeatable Migrations

Flyway has the concept of repeatable migrations, however, Atlas does not. In Flyway repeatable migrations are run last,
if their contents did change. Atlas tries to reproduce this behavior by creating versioned migrations out of each
repeatable migration file found and giving them the character `R` as version suffix.

<Tabs
defaultValue="users"
values={[
{label: 'V1__users.sql', value: 'users'},
{label: 'R__users_view.sql', value: 'users_view'},
{label: '1_users.sql', value: 'users_imported'},
{label: '1R_users_view.sql', value: 'users_view_imported'},
]}>
<TabItem value="users">

```sql
CREATE TABLE `users` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT,
    `age` bigint(20) NOT NULL,
    `name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `age` (`age`)
);
```

</TabItem>
<TabItem value="users_view">

```sql
CREATE VIEW `users_over_30` AS SELECT * FROM `users` where `age` > 30;
```

</TabItem>
<TabItem value="users_imported">

```sql
CREATE TABLE `users` (
    `id` bigint(20) NOT NULL AUTO_INCREMENT,
    `age` bigint(20) NOT NULL,
    `name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `age` (`age`)
);
```

</TabItem>
<TabItem value="users_view_imported">

```sql
CREATE VIEW `users_over_30` AS SELECT * FROM `users` where `age` > 30;
```

</TabItem>
</Tabs>

### Examples

Import existing `golang-migrate/migrate` migration directory:
```shell
atlas migrate import \
  --from "file://migrations?format=golang-migrate" \
  --to "file://atlas-migrations"
```

Import existing Flyway migration directory:
```shell
atlas migrate import \
  --from "file://migrations?format=flyway" \
  --to "file://atlas-migrations"
```

### Reference

[CLI Command Reference](/cli-reference#atlas-migrate-import)
