Welcome Guest, Not a member yet? Register   Sign In
Generate migration file from existing database?
#1

Hello,

I watched a video on how to create database migrations from scratch, which is very handy.
But the thought of creating many large tables from scratch at the beginning of a project
sounds extremely tedious and a huge waste of time, when I can fly through them in Navicat.
Or in most cases am starting with pre-existing tables and data from previous projects.

What is the command to generate the initial migration file from an existing database already
FULL of tables and data?  Thanks!

-Sergio

Bridging the gap between Technical and Creative

VASCOsoft Web Studio   |   AllMyLinks

Reply
#2

@PwrSrg,

What is the database type (MySQL, Oracle, Postgres, etc...)?
Reply
#3

(11-25-2020, 07:20 AM)php_rocs Wrote: @PwrSrg,

What is the database type (MySQL, Oracle, Postgres, etc...)?

MariaDB (MySQL)

Bridging the gap between Technical and Creative

VASCOsoft Web Studio   |   AllMyLinks

Reply
#4

(This post was last modified: 11-25-2020, 03:38 PM by InsiteFX.)

There is no migration command to create a migration from an existing database.

You would need to export it and manually convert it over to a migration file.

The command to create a blank migration file is:

php spark migrate:create [filename]


I have looked into this there is a utility for the Laravel  framework to do just that
To much trouble to write something like that just for a utility.

You can find it here:

Laravel Migrations Generator
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

Migrations and Seeders are great for small projects, but if you have a lot of existing tables or a lot of data, I think it's better to export the database and use SQL scripts.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#6

This would be a great tool. I already have 3 projects where I have to manually write migrations from existing databases
Reply
#7

See https://forum.codeigniter.com/thread-634...#pid324798

You can write code to run the export file in a migration file.
Reply
#8

Thanks. I'll try this
Reply
#9

(This post was last modified: 06-19-2023, 11:25 PM by Corsari.)

(04-23-2022, 06:25 AM)kenjis Wrote: See https://forum.codeigniter.com/thread-634...#pid324798

You can write code to run the export file in a migration file.

allow me to say it is unexpected that in CI4 there is no such utility for at least the popular MySQL DB

I mean the automatic generation of migration for existing tables of an existing DB

Obviously this is not needed for the development phase, you can import whatever in natively SQL or with the aid of phpMyAdmin or others DB tools

The need is when it is time to deliver the app

Sure, it is a specific utility but it is true as well that there are various helpers delivered in/with the Codeigniter suite.

I would put this in a TODO list ( not urgent.... e.g. when spare time is available. I know days have only 24h , what a shame  Wink ) together with a 4th guide in the Shield documentation (I mean one which shows the correct implementation of Shield in a common scenario where to limit the access to admins only for some of the controllers).

R.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB