Setup your development environment

Learn how to pull the boring database repo and start building your own data service app.

Requirements

You should already have your accounts setup for Resend, Fly.io and Stripe so we can access the required envrionment variables for these services.

Steps

There a few steps to follow closely when setting up your boring database for the first time. But we should be up and running in no time!

1. Get the Repo

2. Set up local SQlite Database

If you’ve never setup a SQLite database before, we recommend checking out this tutorial to learn more about it.

If you are using brew you can install sqlite with brew install sqlite and create a new database with sqlite3 sqlite.db.

When you deploy your app, the dockerfile with let Fly will create it’s own sqlite.db file.

3. Set environment variables

4. Seed local SQlite with Prisma

Now you have your .env file set, you can setup your local sqlite database by running first migration of prisma and seed the database with permissions, roles, and admin user.

This seed file will also create products in your stripe dashboard. Please ensure you are using the test environment vairables for your stripe account until you are ready to go live!

To see how the seed file works/make any changes navigate to the prisma/seed.ts

npx prisma migrate dev --name init - will run the initial migration

npx prisma migrate reset - this will force the seed.ts file to run and load your database with data.

You should see success messages logged to the console.

To check the seed has worked you can run npx prisma studio in a new terminal window to start a database UI and explore the tables and records created.

5. Start local environment

If your data has been successfully seeded you can run npm run dev in the terminal to start your app.

You can click one of the purchase buttons to test stripe checkout is correctly linked up.

Or try login with admin@admin.com at Login no One time passcode is sent via email for admin user, you can grab the passcode from the terminal of the running app.

Going live

By this point you should be able to go ahead and customize your boring database app, adding a custom landing page and loading in your dataset.

But when you are ready to deploy for the first time here are the steps:

1. Keeping Local and Production Stripe in sync

The prisma/seed.ts should keep prices in sync for you.

If you ever need to reset your database for a clean start locally you can run npx prisma migrate reset --force. This will remove all the data from the sqlite database and force the seed.ts file to run again. The seed.ts file will fetch products from stripe and populate your plans and products.

2. Launch a new Fly app

Navigate in the terminal to the root of your project and run fly launch. You can follow the prompts to create a new fly app.

If you have not logged into fly through the CLI before you will be prompted to login.

In the Fly CLI you’ll see your app being built from the dockerfile. Once it has been deployed you can run fly apps open in the terminal to open up a browser window with your new app.

Next Steps

That covers the basics of getting your app setup, running locally and deploying to Fly.

When make any changes you can use fly deploy to rebuild and push your new changes to production.

We can do better than that though! In our next step we will cover setting up a Github Action for running tests and deploying our app to fly automatically.