Marijn's avatar

Best way to take over an old legacy project with no migrations

Hi there!

I have the job of migrating an old legacy php + angular app to laravel. So far, I have just copied the databases of the legacy app (it has one main database and one for each tenant/user) and used that to rebuild the application. I know this is definitely not the best practice but when I started 9 months ago I had no clue how to do it better.

No tests

I have reached a point where I am really annoyed with having no tests at all. Yeah, none. I want to start making seeders and testing different parts of the application but I thought it would definitely be best to start with writing migrations files that mirror the structure of the tables in the databases of the old app (and here I would also add indices cause it doesnt have them yet...). What is the best way to go about this? Are there automatic tools that can do this?

0 likes
2 replies
martinbean's avatar

@marijn If you have an existing application and database, then I wouldn’t retrospectively make migrations. Migrations are for tracking changes to your schema. Instead, you can use Laravel’s built-in schema:dump Artisan command. This will, as it says on the tin, dump the current schema. You can now create migrations for any changes you make to the schema in the future, and these will be applied on top of the dumped schema.

For the migration of the actual application codebase, I’d definitely write at least a couple of high-level feature tests that test the core features of the application. You don’t say what the application does so I can’t really give an example, but whatever the main two or three features of your app is, write some feature tests for them. That way, you can start re-factoring and have some testing around the most important functions. As you’re re-factoring, you can obviously write new tests for the code you’re re-factoring, as and when you’re re-factoring it. There’s no point writing unit or integration tests for code that’s going to get moved or trashed soon.

Please or to participate in this conversation.