kaypro4's avatar

Way to "collapse" migrations?

Hello, I'm using SQLite to run unit tests in a docker container in GitLab and am unable to use the 5.2 migrations to create the schema fresh before population because alter statements aren't supported in SQLite and our migrations contain some.

It seems like there should be a way to "collapse" the migrations to a final result that would just be single create statements.

Anyone know of a method to accomplish this? Or a different way of looking at the problem? Right now, I'm having to maintain the SQLite schema manually which is a pretty poor solution.

Thanks Matt

0 likes
2 replies
ejdelmonico's avatar

@kaypro4 Maybe I do not fully understand your question but I use sqlite memory DB for testing all the time without any migration issues via use DatabaseMigrations in my tests and in phpunit.xml:

        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:"/>

I am not aware of an automated way to collapse the migrations for sqlite.

kaypro4's avatar

Thanks for the reply.

The issue I'm having is that SQLite has minimal support for alter table statements.

https://www.tutorialspoint.com/sqlite/sqlite_alter_command.htm

And my migrations utilize more advanced alter statement features so they fail if run on a SQLite file.

My thinking is that I don't really need to run all the migrations in a test DB since I really only need the resulting schema which will all be create statements. I think there is a "schema load" feature in Ruby that does something like this so wondering if Laravel folks had ported the concept. Seems like it might be handy.

Thanks again.

Please or to participate in this conversation.