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:
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.
-
Change the
DATABASE_URL
in the.env
file to the desired database path..env DATABASE_URL="file:/path/to/dev.db" -
Initialize the database to complete the setup.
Terminal window npx prisma migrate deploy
Using MySQL
-
Install the
mysql2
package with the following command:Terminal window npm install mysql2 -
Change the
provider
in thedb/schema/main.prisma
file tomysql
.db/schema/main.prisma datasource db {provider = "mysql" // change hereurl = env("DATABASE_URL")} -
Change the
DATABASE_URL
in the.env
file to your MySQL connection details..env DATABASE_URL="mysql://root:@localhost:3306/accella_dev" -
Initialize the database to complete the setup.
Terminal window npx prisma migrate deploy
Using PostgreSQL
-
Install the
pg
package with the following command:Terminal window npm install pg -
Change the
provider
in thedb/schema/main.prisma
file topostgresql
.db/schema/main.prisma datasource db {provider = "postgresql" // change hereurl = env("DATABASE_URL")} -
Change the
DATABASE_URL
in the.env
file to your PostgreSQL connection details..env DATABASE_URL="postgresql://test:password@localhost:5432/accella_dev" -
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
.
datasource db { provider = "sqlite" url = env("DATABASE_URL")}
The initialization process for the ORM, Accel Record, is written in 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.