Database migrations in Joomla

2019-07-05 05:48发布

问题:

Is there any way of using database migrations with Joomla? I'm looking for a mechanism like the one found in Rails or Symfony.

I would like to apply changes to the database whenever my model changes, e.g. adding a column, creating a new relationship, dropping some tables,...

In this question, the accepted answer seems like a very cool option, but I don't know if there is something specific to Joomla.

Thanks!

回答1:

If you want to update your own component's DB schema you can refer to the following thread: http://forum.joomla.org/viewtopic.php?p=1607199

If you need just migrations without components, check these standalone solutions:

  • https://github.com/davejkiger/mysql-php-migrations
  • https://github.com/Billiam/MySQL-PHP-AutoMigrations


回答2:

I'm working a lot with Joomla for functionnalities implementations and the model changes are made by sql queries mostly or via phpMyAdmin.

Also we do not changes the model of joomla tables (core or plugins one) because the source code without modifications will not handle the changes. We are only adding tables using external ids (like jos_users id).

Futhermore if you change the model of joomla tables, you will not be able to update it (or the plugins impacted) easily.



回答3:

there is 2 real ways to do migration in Joomla, and each based really on one solution:

1) Just place you SQL changes(like ceate table, or alter, or any thing) /administrator/components/com_admin/SQL/updates/YOU_DB_ENGINE/anyfilename.sql go to web interface then /administrator => extension => manage => database and simple press fix.

2) you can take a look at /administrator/components/com_installer/models/database.php and implement you custom migration process based on this so you can use custom folder