Source control for PostgreSql Data base with git - Stack Overflow
PostgreSQL database in repository
How can I put a database under git (version control)? - Stack Overflow
Version control for a postgres db's user defined functions?
Generally the modern approach to doing this these days is to learn to use propel ORM or Doctrine ORM, which will version your database for you and keep the structure in sync as you commit the basic schema (in an xml format) and migrations.
PHP ORMs: Doctrine vs. Propel Has more about propel vs. doctrine.
You can use some tool that can generate text representation of db schema into files in some folder under vcs.
To see adequate working tree status you'll need to run schema generation before git status.
Before update from remote (git fetch && git rebase or git pull) you'll need to get db schema into worktree.
If that version differs from latest version in HEAD then you'll need to revert it in db or commit.
After update you'll need to get db schema into worktree again, check out diff and revert it in real db until db schema get will produce clean worktree.
P.S. I'm using this technique for MsSql db schemas in git. I even added db data to repo, this may be useful too.
Hi, I’m a beginner at web development so I’m sorry for the dumb question but I recently made a project for a course I’m following that made use of a database I had created in PostgreSQL.
Now, I want to ask, if I want to upload this project on Github, how do I upload the database or the PostgreSQL content I used? What would be the right way of adding a project like that on my Github?
Take a database dump, and version control that instead. This way it is a flat text file.
Personally I suggest that you keep both a data dump, and a schema dump. This way using diff it becomes fairly easy to see what changed in the schema from revision to revision.
If you are making big changes, you should have a secondary database that you make the new schema changes to and not touch the old one since as you said you are making a branch.
I'm starting to think of a really simple solution, don't know why I didn't think of it before!!
- Duplicate the database, (both the schema and the data).
- In the branch for the new-major-changes, simply change the project configuration to use the new duplicate database.
This way I can switch branches without worrying about database schema changes.
EDIT:
By duplicate, I mean create another database with a different name (like my_db_2); not doing a dump or anything like that.