# Can't run migration for separate slice

**URL:** <https://discourse.hanakai.org/t/cant-run-migration-for-separate-slice/1066>\
**Category:** issues\
**Created:** [November 28, 2024, 11:36am UTC](https://discourse.hanakai.org/t/cant-run-migration-for-separate-slice/1066 "2024-11-28T11:36:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladimirtcats](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/vladimirtcats/32/784_2.png) [@vladimirtcats](https://discourse.hanakai.org/u/vladimirtcats)\
**Post date:** [November 28, 2024, 11:36am UTC](https://discourse.hanakai.org/t/cant-run-migration-for-separate-slice/1066/1 "2024-11-28T11:36:43Z")

</div>

Hi everyone!

I have 3 separate migration in my app:  
**20241114121339\_users** , **20241118133344\_books.rb** , **20241122114836\_apps.rb**

I decided to create separate slice for api and put migration into  
slices/api/config/db/migrate/20241128111648\_create\_admin\_users.rb

Then I run the command:

```auto
bundle exec hanami db migrate

```

I got:

```auto
WARNING: Database myapp_test is configured for multiple config/db/ directories:

- config/db
- slices/admin_api/config/db

Using config in "my_app" slice only.

=> database my_app_test migrated in 0.0007s
WARNING: Database my_app_test is configured for multiple config/db/ directories:

- config/db
- slices/admin_api/config/db

Using config in "my_app" slice only.

=> my_app structure dumped to config/db/structure.sql in 0.0579s

```

Ant it didn’t change config/db/structure.sql

then I tried to run:

```auto
bundle exec hanami db migrate --slice api

```

And I got error:

```auto
/usr/local/bundle/gems/sequel-5.86.0/lib/sequel/extensions/migration.rb:783:in `get_applied_migrations': Applied migration files not in file system: 20241114121339_create_users, 20241118133344_create_books.rb, 20241122114836_create_apps.rb (Sequel::Migrator::Error)

```

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/timriley/32/621_2.png) [@timriley](https://discourse.hanakai.org/u/timriley)\
**Post date:** [November 29, 2024, 9:00am UTC](https://discourse.hanakai.org/t/cant-run-migration-for-separate-slice/1066/2 "2024-11-29T09:00:48Z")

</div>

Thanks for raising this here, @vladimirtcats!

Am I right in presuming that you only have a single database (i.e. a single `DATABASE_URL`) for your app?

Hanami’s database layer is designed for each distinct database to have its config (e.g. migrations) reside in a single slice only. By trying to add a new migration file to a slice when the rest of your config is elsewhere, you split the config across two places. This is why you receive the warning message.

If you’re sharing a single database across multiple slices, you should keep the config all together. In this case, I recommend you keep everything in `config/db/` like you started with.

---

<div class="post-metadata">

**Author:** ![vladimirtcats](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/vladimirtcats/32/784_2.png) [@vladimirtcats](https://discourse.hanakai.org/u/vladimirtcats)\
**Post date:** [November 29, 2024, 12:23pm UTC](https://discourse.hanakai.org/t/cant-run-migration-for-separate-slice/1066/3 "2024-11-29T12:23:18Z")

</div>

Yes. I only use one database  
I would like to separate migration on slices to separate logic. Maybe it makes sense to introduce additional option to run migration in certain slice:)

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/timriley/32/621_2.png) [@timriley](https://discourse.hanakai.org/u/timriley)\
**Post date:** [November 29, 2024, 12:26pm UTC](https://discourse.hanakai.org/t/cant-run-migration-for-separate-slice/1066/4 "2024-11-29T12:26:19Z")

</div>

Thanks for confirming this 🙂

In this case, you’ll need to keep all your database config (such as migrations) in a single `config/db/` location only.

This is an intentional design choice. A single database is a single thing. We want to keep all related config also in a single place. This helps ensure that (a) the user understands what is going on, and (b) our code reliably and consistently operates on that database. If config is spread around then it becomes a recipe for user-confusion and inconsistently managed databases.

---

<div class="post-metadata">

**Author:** ![alassek](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/alassek/32/532_2.png) [@alassek](https://discourse.hanakai.org/u/alassek)\
**Post date:** [December 1, 2024, 12:21am UTC](https://discourse.hanakai.org/t/cant-run-migration-for-separate-slice/1066/5 "2024-12-01T00:21:28Z")

</div>

> [@timriley](#):
>
> If config is spread around then it becomes a recipe for user-confusion and inconsistently managed databases.

To expand on that: Hanami supports Slices having their own, independent DB configuration. In that case, you _would_ have configuration in the Slice directory.

In order to reduce the boilerplate of configuring your persistence, the presence of a `config/db` directory tells the DB provider to enable itself for that context.

If Hanami were to support multiple locations for migrations, this would mean requiring more boilerplate configuration for all apps, and the location would no longer communicate the context in which it is being used.
