Database Generation
Once you have valid ADM models defined, you can automatically generate a database for your project using ADM's database generation tool.
Create Your Database:
In order to take advantage of automated database creation, you need to make sure you've setup your database configuration. If you haven't done that yet, Click Here to view instructions on doing so. The other thing you'll need (as of me writing this), is command line access. In the future, an in-browser visual interface to the database creation tool may be added, but for now it's just a command line tool.
To automatically generate a database based on your model definitions you need to do the following:
- Open a Terminal.
- If on a Mac, open your Applications, click the Utilities folder, and then select the "Terminal" application.
- If on a PC, hit your Windows Key + R to open the "Run" window, then type in "cmd" and hit enter.
- If on Linux you don't need me to tell you how to do this, but since I can't help myself I'll mention that Ubuntu and Mint both map the terminal to Ctrl+Alt+T.
- Navigate to your project's directory.
- If you are XAMPP, MAMP, etc, that will likely be wherever you installed that and then in the "htdocs" folder within.
- Once at the root of your project, type "php ADM.php dbBuild" to have ADM build your database for you.
php ADM.php dbBuild
If all went well, you should see a flurry of output to the console and your database should be ready to go!
Of course, if you want to read through the documentation in the Models page to fully understand how the mappings work for the purpose of setting your database(s) up manually, you can, although that takes more expertise and effort.
Empty a Database
So chances are you'll be making changes to your models throughout development and will need to rebuild your database each time. In order to make use of the automated creation tool again, you'll need to empty out any database(s) you're using by deleting all the existing tables. To speed up this process, the database generation tool also includes a command to delete all the existing tables.
To make this happen, you need to use the "dbEmpty" command and then specify a database connection from your project's database config file:
php ADM.php dbEmpty NameOfConnection
Automatic Data Loading
By default, when you run the "dbBuild" command, ADM will look for a file named "data.php" in the following directory:
/includes/data.php
If it finds a matching file, it will include it after it does the build. The expected use case is "data.php" uses Cora's database class to run some Insert commands to load data into the database for you. However, the file can do whatever you want, and you can use whatever tools you want within it (obviously). It's just a way for you to execute some code to populate your database with test data during development.
If you want to include a file other than "data.php", you can specify a different file after the build command like so:
php ADM.php dbBuild myfile.php