- Golang development environment
- Postgres 10 server
For data model changes you'll need:
- golang-migrate cli tool installed and in your path
- sqlboiler installed
Also recommended is fresh for automatic recompiling.
- Copy
sqlboiler.sample.toml.sampleandconfig.sample.jsonto new files - removing the.sample - You'll need to at least change the Database Name (
<DATABASE>), DB User (<DBUSER>) and DB Password (<DBPASS>) in those files to a suitable config for your system.- It's a good idea to use a unique database and user and a random password to avoid issues with your dev environment
- You may need to change the host and port entries to reflect your local setup. The example fields in
config.sample.jsonare the defaults. config.sample.jsonis used by the live application, whilesqlboiler.sample.tomlis only used to generate new datamodels from database data.- the root "development" flag is only used to perform migrations from files.
In the subdirectory helperTool of this repo is package that compiles a helper tool.
This should be built via go build and the executable moved into your path.
- By default the helper tool will look for your config file in the working directory
- By default the helper tool will use the postgres user
postgres(this needs to be a root user) - By default the helper tool will use the postgres password
rootpassword - If you've changed the docker config these may need to be specified - run the tool with the
/hoption to get help
The following sections will make use of the helper tool to create databases and users.
- Setup the config file with the correct:
- database host
- database port
- the desired database name to use (this will be created and if this exists, it will be overwritten)
- the desired user to user (this will be created and if this exists, it will be overwritten)
- the desired user's password
- run the helper tool with the
createDBcommand - if no errors are encountered, the base setup is complete!
- You'll need to have completed the database setup step above.
- You'll need to have run the server at least once to have crated the required tables
- run the helper tool with the
createUsercommand. This command takes the following parameters:username- the desired username for the new userpassword- the password for the new useremail- the email for the new user- (optional)
superadmin- if the user is a super/root administrator. defaults to false
- if no errors are encountered, the user was created!
- Ensure you have the development flag turned on to test your migration scripts
- run the helper tool with the
createMigrationcommand. This command takes the following parameters:directory- the root directory of this repository (if the helpertool is being run in the helperTool directory, then this will be either..\or../depending on your os)name- the name of the migration to create. Should be related to what the migration does, should probably be enclosed in quotes. The tool will replace whitespace with_, and non-alpha numeric characters with-
- Specify the migration syntax in the new files created in the
datasource/migrations/directory - Test your migration via either:
- compiling and running the server with the development flag turned on
- manually running the migration via
migrate -source file://datasource/migrations -database postgres://<DBUSER>:<DBPASS>@localhost:15432/<DBNAME>?sslmode=disable up
- Once your migration has the correct SQL, regenerate the bindata using the helperTool's
updateBindatacommanddirectory- the root directory of this repository (if the helpertool is being run in the helperTool directory, then this will be either..\or../depending on your os)
- Then generate the models:
- Ensure you have a configured
sqlboiler.sample.tomlfile - Run
sqlboiler psql -o datamodels_raw -p datamodels_rawfrom the root of the repo
- Ensure you have a configured