Configure SQLite for Strapi on Platform.sh

Strapi uses SQLite database by default when it’s run on a local machine. When you create a new Strapi project, you can use SQLite or a custom database installation (PostgreSQL, MongoDB, or MySQL). Since Strapi uses SQLite by default, you don’t need much configuration, just follow these steps:

  1. In your Strapi project, install the Platfom.sh config reader.

    npm install platformsh-config
    
    # or for Yarn
    yarn add platformsh-config
  2. Create a new Strapi project and select Quickstart as the installation type. This automatically configures Strapi for SQLite

    npx create-strapi-app <APP_NAME>
  3. In the config folder, locate the database.js file, and replace its content with the following:

    const config = require("platformsh-config").config();
    const path = require("path");
    
    
    let dbRelationship = "pg";
    
    // Strapi default sqlite settings.
    let pool = {};
    let connection = {
    connection: {
    client: 'sqlite',
    connection: {
    filename: path.join(\_\_dirname, '..', process.env.DATABASE_FILENAME || '.tmp/data.db'),
    },
    useNullAsDefault: true,
      },
    };
    
    if (config.isValidPlatform() && !config.inBuild()) {
    // Platform.sh database configuration.
    try {
    const credentials = config.credentials(dbRelationship);
    console.log(`Using Platform.sh configuration with relationship ${dbRelationship}.`);
    
        pool = {
          min: 0,
          max: 10,
          acquireTimeoutMillis: 600000,
          createTimeoutMillis: 30000,
          idleTimeoutMillis: 20000,
          reapIntervalMillis: 20000,
          createRetryIntervalMillis: 200,
        };
    
        connection = {
          connection: {
            client: "postgres",
            connection: {
              host: credentials.ip,
              port: credentials.port,
              database: credentials.path,
              user: credentials.username,
              password: credentials.password,
              ssl: false
            },
            debug: false,
            pool
          },
        };
    
    }
    catch (e) {
    // Do nothing if 'pg' relationship isn't found.
    // Database configuration falls back on the SQLite defaults.
      }
    } else {
    if (config.isValidPlatform()) {
    // Build hook configuration message.
    console.log('Using default configuration during Platform.sh build hook until relationships are available.');
    } else {
    // Strapi default local configuration.
    console.log('Not in a Platform.sh Environment. Using default local sqlite configuration.');
     }
    }
    
    // strapi-api/config/database.js
    module.exports = ({ env }) => ( connection );

This setting deploys your Strapi application with an SQLite database.