CodeIgniter Forums
Database Schemas Module - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Addins (https://forum.codeigniter.com/forum-34.html)
+--- Thread: Database Schemas Module (/thread-74444.html)



Database Schemas Module - MGatner - 09-24-2019

Hi all- I have two new modules I'm excited about. The first stands alone and assists with handling database structures. It is early in its life but can already map directly from a database or from a PHP file and provide a flexible and comprehensive schema for your application. I hope for this to be a builder block for many other uses:

Tatter/Schemas - Database schema management, for CodeIgniter 4

Basic usage:

1. Install with Composer: `> composer require tatter/schemas`
2. Use the CLI to generate a schema: `> php spark schemas`

The CLI command will prompt for parameters but can also be scripted for your handlers. E.g. to run from a cron to periodically cache your schema you might do:
PHP Code:
php spark schemas database model -export cache 

Some current and future uses for this module:
  • View your entire database mapped out in a cascading structure
  • Read or detect table relationships for easy object-relation mapping (see e.g. Tatter\Relations)
  • Get helpful advice on optimizations to your database structure with schema analysis
  • Backup, restore, or deploy an entire database structure between servers or environments
  • Generate CodeIgniter 4 migration files from an existing database
  • Transfer projects to CodeIgniter 4 by reading schema files from other supported formats

Thanks for reading! I'm always glad for feedback and suggestions, feel free to leave a comment here or check out the repo at https://github.com/tattersoftware/codeigniter4-schemas.


RE: Database Schemas Module - MGatner - 07-13-2020

I think most people are using this as part of Tatter\Relations, but for anyone accessing Schemas directly the latest version changes the cache key to use dashes as separators instead of colons. This helps with Windows compatibility where the cache driver was failing because of the illegal file names.

The cache is only referenced internally, but if for some reason you are accessing it manually please check your code after updating.


RE: Database Schemas Module - aschmitz - 10-03-2020

Hey MGatner,

thanks for the great module, espacially Tatter\Relations comes in quite handy for me, as it resembles the way I used to merge relations together manually before.

Right now I am dealing with synchronising databases between my production and development environment.
As far as I see, this was done in CI3 witht the backup method which is disabled for mySQLi in CI4.

Now in the Tatter\Schemas module, the desired feature list includes exporting/importing whole databses. Is there any plans already on when and/or how this could be accomplished? Smile


RE: Database Schemas Module - MGatner - 10-03-2020

No plans so far! I’ve kind of been waiting to see what kind of use and interest there is for the existing modules before committing to a development roadmap. I will say that, while the intent is to have the ability you described, I would highly recommend that you implement Migrations. I cannot stress how important it is for scalar development that the database state be tied to repository state, and synching the database directly is going to make that very difficult.


RE: Database Schemas Module - aschmitz - 10-07-2020

Alright, going with migrations seems reasonable I guess Smile So far I only used them for changes to the schema and not for data.


RE: Database Schemas Module - MGatner - 10-07-2020

I guess I misunderstood your question. Migrations and Schemas both are only intended to work with the table schema, not the data. I could see using migrations for some “fixtures”, like project-specific settings that would never change, but in most cases a Seeder would be more appropriate. If you’re looking for a complete database copying solution you might be better handling that outside the framework. I question though the desire to copy data from development to production - do you even want that?


RE: Database Schemas Module - aschmitz - 10-16-2020

Thanks for the discussion! I guess eventually I went wrong here, thinking that Schemas would also handle data in the end (the plugin name could have been a hint though...).
In my case, I sometimes need the data from the production environment on my local setup to generate special lists, reports etc. which I have implemented in another (not-online) project and I cannot access mysqldump as SSH is disabled.
If anybody else has a similar specific use case, I ended up importing mysqldump-php into ThirdParty which works nicely.

Will keep watching (and using) Schemas and Relations, thanks for that :-)


RE: Database Schemas Module - nc03061981 - 10-16-2020

Thanks @MGatner