-
Notifications
You must be signed in to change notification settings - Fork 387
Satellite how to new table
The purpose of this document is to outline the steps to create a new table in the Satellite.DB.
DBX
is a tool to generate database schemas and code to operate with it. Satellite.DB uses DBX
to generate the database code for SQLite and PostgreSQL.
-
Storj repo is cloned locally.
-
Install
DBX
package.DBX
has a dependency on Mercerial, so you may need to install that if you get an error likehg clone -U [...] "hg": executable file not found in $PATH
.
$ go get -v storj.io/dbx
Assumes all steps occur from the home directory of the https://github.com/storj/storj repo.
-
Add a table model in
satellite/satellitedb/dbx/satellitedb.dbx
. SeeDBX
docs for details on creating a model: https://github.com/spacemonkeygo/dbx. -
Generate the
*.dbx.go
code by running the following commands:
$ cd satellite/satellitedb/dbx/
$ go generate
- Generate the
locked.go
code for the database:
$ cd ..
// from satellite/satellitedb dir
$ go generate
-
Add a migration to
satellite/satellitedb/migrate.go
. The version must be incremented for each migration. You can add multiple migration queries in one migration. -
Add new testdata file to
satellite/satellitedb/testdata/postgres.vX.sql
,where X matches the version of the migration. To create a new testdata file, copy the last testdata file and add the migration changes to this new copy. If the migration adds a new table, use-- NEW DATA --
at the end and add lines that insert data into the table (this is used for testing future migrations).