Skip to content

Database Configuration

By default, Accella is configured to use SQLite as the database. If you do not wish to change this, you can skip this section. Refer to this section if you want to use MySQL or PostgreSQL as the database engine or if you want to change the SQLite connection details.

Prisma is used for table definitions and migrations, and Accel Record is used as the ORM.

Initializing the Database

To initialize the database after changing the configuration, run the following command:

Terminal window
npx prisma migrate deploy

Changing Database Configuration

This section explains how to switch database engines and specify connection details.

Changing the SQLite Database

By default, Accella is set to use SQLite. Here are the steps to change the SQLite database. The better-sqlite3 package is used for SQLite connections.

  1. Change the DATABASE_URL in the .env file to the desired database path.

    .env
    DATABASE_URL="file:/path/to/dev.db"
  2. Initialize the database to complete the setup.

    Terminal window
    npx prisma migrate deploy

Using MySQL

  1. Install the mysql2 package with the following command:

    Terminal window
    npm install mysql2
  2. Change the provider in the db/schema/main.prisma file to mysql.

    db/schema/main.prisma
    datasource db {
    provider = "mysql" // change here
    url = env("DATABASE_URL")
    }
  3. Change the DATABASE_URL in the .env file to your MySQL connection details.

    .env
    DATABASE_URL="mysql://root:@localhost:3306/accella_dev"
  4. Initialize the database to complete the setup.

    Terminal window
    npx prisma migrate deploy

Using PostgreSQL

  1. Install the pg package with the following command:

    Terminal window
    npm install pg
  2. Change the provider in the db/schema/main.prisma file to postgresql.

    db/schema/main.prisma
    datasource db {
    provider = "postgresql" // change here
    url = env("DATABASE_URL")
    }
  3. Change the DATABASE_URL in the .env file to your PostgreSQL connection details.

    .env
    DATABASE_URL="postgresql://test:password@localhost:5432/accella_dev"
  4. Initialize the database to complete the setup.

    Terminal window
    npx prisma migrate deploy

Configuring a Test Database

To change the test database configuration, update the DATABASE_URL value in the .env.test file. For more details, refer to the Testing page.

Advanced Database Configuration

Accella uses Prisma for table definitions and migrations. The database connection configurations for Prisma are written in db/schema/main.prisma.

db/schema/main.prisma
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}

The initialization process for the ORM, Accel Record, is written in src/config/initializers/database.ts.

src/config/initializers/database.ts
import { initAccelRecord } from "accel-record";
import { getDatabaseConfig } from "../../models";
export default async () => {
await initAccelRecord(getDatabaseConfig());
};

You can make more detailed configurations by changing these sections. Refer to the respective documentation for more information.