https://github.com/source-academy/stories-backend
Backend of Source Academy extension for Stories support.
https://github.com/source-academy/stories-backend
Last synced: 11 months ago
JSON representation
Backend of Source Academy extension for Stories support.
- Host: GitHub
- URL: https://github.com/source-academy/stories-backend
- Owner: source-academy
- Created: 2023-06-26T03:58:36.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-11T23:49:18.000Z (over 1 year ago)
- Last Synced: 2025-01-01T14:09:06.745Z (over 1 year ago)
- Language: Go
- Size: 233 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Backend for Source Academy Stories
[](https://coveralls.io/github/source-academy/stories-backend?branch=main)
## Setup
### Installing languages and tools required
Install Golang and PostgresSQL. We recommend using a version manager like [asdf](https://asdf-vm.com/) to manage your installations. Use the versions of the tools listed in the `.tool-versions` file.
* (For `asdf` only) if not already installed, install the necessary plugins:
```bash
asdf plugin add golang
asdf plugin add postgres
```
* Install the required versions of the tools:
```bash
asdf install golang 1.21.5
asdf install postgres 14.8
```
To work with and debug the API, we also strongly recommend installing tools like [Postman](https://www.postman.com/downloads/).
### Setting up git hooks
We use pre-commit and pre-push hooks to ensure that code is formatted and linted before committing and pushing. To set up the hooks, run the following commands:
```bash
make hooks
```
**Notes:**
* Hooks only work on macOS/Linux. Support for Windows is coming soon.
* You will need to install golangci-lint locally for git hooks to work. See [Running linter](#running-linter) for instructions.
### Setting up the database
#### Creating the database
Run the following command to create the database:
```bash
make db_create
```
#### Migrating the database
For this step onwards, make sure you have your environment variables set up correctly. See [Setting up environment variables](#setting-up-environment-variables) for more details.
Run the migration target to migrate the database:
```bash
make db_migrate
```
By default, the migration target will run all pending migrations (visible using `make db_status` command). To only run a certain number of migrations forward, use the `steps` argument:
```bash
make db_migrate steps=1
```
#### Rolling back migrations
To roll back the most recent migration, run the following command:
```bash
make db_rollback
```
To roll back a certain number of migrations, use the `steps` argument:
```bash
make db_rollback steps=1
```
### Setting up environment variables
Copy `.env.example` to `.env` and fill in/modify the required values as needed.
## Development
### Starting the server
```bash
make dev
```
### Running linter
Step 1: Install [golangci-lint](https://golangci-lint.run/usage/install/#local-installation) locally.
Step 2: Run the lint commmand:
```bash
make lint
```
### Testing your code
By convention, test files are named `*_test.go` and are placed in the same directory as the code they are testing.
To run all tests:
```bash
make test
```
To run all tests and view test coverage:
```bash
make coverage
```
## Building for production
```bash
make build
```