Commit 8fe66072 authored by Ben Beltran's avatar Ben Beltran

Document migrations in the DB

parent f955e9e8
......@@ -40,4 +40,31 @@ This project uses rethinkdb as a database, which exposes an
admin panel on port 8080. You can open it in a browser by
running `npm run db:admin` which will open `http://localhostt:8080`
## Creating migrations for the database
This project uses `migrate` to create and run migrations in the
database. If you want to create, modify or remove a table you
should first create a migration using `npx migrate create <migration_name>`
where the `<migration_name>` describes the operation you want to do using
the imperative mood. Here's some examples:
* `npx migrate create add_posts_table`: Add a table called posts
* `npx migrate create add_forum_id_to_topics`: Add a `forum_id` column to
the `topics` table
* `npx migrate create add_position_index_to_forums`: Adds an index called
position to the forums table
* `npx migrate create remove_posts_table`: Removes a table called posts
Migrations will be created in the `migrations` directory with a timestamp.
They will run from oldest to newest when running `npm run db:migrate`.
Inside these files you will find an `up` and `down` function. `up` should
perform the main action of the migration (eg. for `add_posts_table` it should
have the code to create that table), and the `down` function should have
the opposite action (eg. in the previous example, it would have code to
remove that table)
The file `db/helpers.js` has a set of helper functions for some common
operations used when dealing with the database: gettting a connection
to the database, and getting a connection with a database selected.
[node]: https://nodejs.org/en/
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment