After cloning, make the following case sensitive global text replacements:
PACKAGE-> your lowercase package name (follow npm naming conventions, e.g., lowercase, no spaces)APP_NAME-> Your human friendly app name
Don't forget to manually rename PACKAGE.code-workspace, replacing PACKAGE for the name of your project.
Finally, delete this section from the README and run yarn to properly link dependencies.
-
Node 18+
-
This project is a monorepo, so Yarn was chosen for better dependency management
-
Install dependencies
yarn
-
Copy
packages/api/.env.sampletopackages/api/.env.localcp packages/api/.env.sample packages/api/.env.local
If you don't have Postgres installed already, see the
Installation and Usesection below.After installing, create a DB with the name
PACKAGE(or use another name and overrideDATABASE_URLin your.env.local).Installation and Use
We recommend using Postgres.app as the installation doesn't require a password and is generally easier to use that the traditional Postgres app below.
During the installation process (if you follow the steps on postgresql.org), you will be prompted to set a password - make sure to use something you'll remember.
If you'd like a visual way of viewing or editing your local database, try using TablePlus.
You can seed the database using the
mikro-orm/clitool.You can drop, create, migrate, and seed the database any time you need with this command (run from
packages/api):yarn mikro-orm migration:fresh --seed DatabaseSeeder
⚠️ NOTE: Running the above command will delete all data in your databaseTo run migrations locally, use
yarn migratefrom the root. If you ever want to replace your db contents with a fresh setup, runyarn db:fresh.The process to update all packages is a little painful because ALL Mikro-ORM dependencies across BOTH packages must be kept in sync. Run both commands below (after modifying the version to match whatever target needed)
# API yarn workspace @PACKAGE/api add @mikro-orm/core@^6.0 @mikro-orm/knex@^6.0 @mikro-orm/postgresql@^6.0 mikro-orm@^6.0 # DB yarn workspace @PACKAGE/database add @mikro-orm/cli@^6.0 @mikro-orm/core@^6.0 @mikro-orm/knex@^6.0 @mikro-orm/migrations@^6.0 @mikro-orm/postgresql@^6.0 @mikro-orm/seeder@^6.0 mikro-orm@^6.0
In order to debug an issue locally, it can be helpful to mirror the prod DB locally. When doing so, make sure to avoid actions that will trigger text messages because user data is REAL. Always re-seed the DB after fixing your issue to avoid sending erroneous texts.
⚠️ WARNING: Make sure to follow these steps closely. Making an error below has the potential to overwrite production data if your token allows for write access.- Open TablePlus (no need to connect to a DB)
- Go to
File > Backup(Windows steps TBD), choose your production database connection - Select the prod database
- Make sure the Postgres version is
PostgreSQL 14.0and set the options to be--no-ownerand--format=custom - Click
Start Backup - (OPTIONAL) Drop all current data to ensure your local copy is an exact replica, otherwise some local data may persist
- Open a connection to your local database, select all tables and functions (
command + aon macOS), right click, and choose "Delete" - When prompted, check the option for
Cascadeand clickOK
- Open a connection to your local database, select all tables and functions (
- Wait for the backup to finish and then go to
File > Restore(Windows steps TBD), choose your local database connection - Remove all flags from the left hand side (primarily,
--single-transactionwhich will cause your restore to fail on conflict) - Select your database on the right hand side
- Click
Start restore
If you add data manually to your database (through a tool like TablePlus) and do NOT let Postgres assign an
idautomatically, you will disrupt the sequence for that table that determines the next availableidto assign. If that happens, perform the following queries to restart it.Find the appropriate sequence name:
SELECT sequence_schema, sequence_name FROM information_schema.sequences ORDER BY sequence_name;
Restart the sequence with a new id:
ALTER SEQUENCE "YOUR_TABLE_SEQUENCE" RESTART WITH THE_NEXT_ID_TO_ASSIGN;
(e.g.,
ALTER SEQUENCE "Provider_id_seq" RESTART WITH 11;)To configure Slack notifications for certain events, create a Slack app use the following manifest after selecting
From an app manifest(NOTE: watch out for whitespace issues when copying):display_information: name: APP_NAME Dev (YOUR_FIRST_NAME) description: Dev bot for testing integrations background_color: '#000000' features: bot_user: display_name: APP_NAME (YOUR_FIRST_NAME) always_online: false oauth_config: scopes: bot: - chat:write.public - chat:write settings: org_deploy_enabled: false socket_mode_enabled: false token_rotation_enabled: false
After creating the app, use the sidebar and go to
Install Appand request to install the app to your workspace. Once approved, head back to this section andInstall to workspace.After installation, copy the
Bot User OAuth Tokenvalue (starting withxoxb-) and use that for yourSLACK_BOT_TOKEN.Channel IDs can be obtained by right clicking a channel in the sidebar and removing the last path value from the URL.
-
Start the development server
yarn dev
When you see this success message, open the url to load the site
🚀 Listening at http://localhost:3000
The server starts before Next.js finishes compiling, so the first time may take a little bit to load
-
After your initial setup, you'll need to run your database migrations:
yarn migrate -
Start developing
APP_NAME is containerized to make deployment efficient and to prevent vendor-dependence for our cloud environment
- Installing relevant dependencies
- Duplicate
.env.docker.sampleas.env.dockerand modify values as needed - Downloading Docker Desktop and start it
- Optionally modify
Settings > Resources > Advancedto provide more resources to Docker and speed up your build commands
- Optionally modify
- Run
yarn docker:buildfrom the root to build your image - Run
yarn docker:runto start your container - Visit
localhost:3001to use the app running in Docker
packages/api/.env.local is used as the base for all environment variables but .env.docker will override any specified environment variables as needed.
On macOS Postgres user/pass is typically not required. If you do not use one in your API .env.local, you WILL need to specify one in .env.docker; the password is typically blank (no value needed) and your username is typically your machine user (use whoami in terminal).
If you are unable to start your Docker app, make sure the steps above have been followed, then:
- Check the accuracy of your
.env.dockerandpackages/api/.env.localvalues (the former will override the latter) - Make sure no quotes are used in either file; Docker does not remove them and your value will include them
- You can use Docker Desktop to inspect the environment:
Docker Desktop > Containers / Apps > PACKAGE(environment variables can be found on theInspecttab)