How to include MySQL database schema on GitHub?

Kay picture Kay · Apr 29, 2013 · Viewed 15.3k times · Source

Stackoverflow and MySQL-via-command-line n00b here, please be gentle! I've been looking around for answers to my question but could only find topics dealing with GitHubbing MySQL dumps (as in: data dumps) for collaboration or MySQL "version control" via GitHub, neither of which tells me what I want to know:

How does one include MySQL database schemas/information on tables with PHP projects on GitHub?

I want to share a PHP project on GitHub which relies on the existence of a MySQL database with certain tables. If someone wanted to copy/make use of this project, they would need to have these particular tables in place to make the script work (all tables but one are empty in the beginning and only get filled by the user over time, via the script; the non-empty table holds three values from the start). How does one go about this, what is common practice?

  • Would I just get a (complete) dump file of my own db/tables, then delete all the data parts (except for that one non-empty table), set all autoincrements to zero and then upload that .sql file to GitHub along with the rest of the project? OR
  • Is it best/better practice to write a (PHP) script with which the (maybe not-so-experienced) user can create these tables without having to use mysqldump/command line magic?

If solution #1 is the way to go, would I include further instructions on how to use such a .sql file?

Sorry if my questions sound silly, but as I said above, I myself am new to using the command line for MySQL-related things and had only ever used phpMyAdmin until yesterday (when I created my very first dump file with mysqldump - yay!).

Answer

nietonfir picture nietonfir · Apr 29, 2013

Common practice is to include an install script that creates the necessary tables, so solution #2 would be the way to go.

[edit] That script could ofc just replay a dump. ;)

You might also be interested in migrations: How to automate migration (schema and data) for PHP/MySQL application