Instead of providing a live databaseUrl, you can provide a migrationsDir path. SafeQL will then automatically synchronize your .sql migration files to a temporary "shadow database". This shadow database is used to retrieve type information for your queries, which is useful when keeping a live database in sync with migrations is difficult.
Important: The Shadow Database and connectionUrl
- The shadow database is created, run against, and dropped/recreated every time ESLint initializes.
- If your PostgreSQL superuser credentials differ from the default (
postgres://postgres:postgres@localhost:5432/postgres), you must configure the connectionUrl option. connectionUrl is used to create the shadow database, whereas databaseUrl (if used) is for your app. If using migrationsDir, connectionUrl provides the superuser/role permissions needed to run createdb and dropdb.
Flat Config Example:
import tseslint from "typescript-eslint";
import safeql from "@ts-safeql/eslint-plugin/config";
export default tseslint.config(
{
languageOptions: {
parserOptions: {
projectService: true,
},
},
},
safeql.configs.connections({
connections: [
{
migrationsDir: "./migrations",
targets: [{ tag: "db.sql" }],
// connectionUrl: "postgres://pguser:password@localhost:5432/postgres"
},
],
})
);
// eslint.config.js
import tseslint from "typescript-eslint";
import safeql from "@ts-safeql/eslint-plugin/config";
export default tseslint.config(
{
languageOptions: {
parserOptions: {
projectService: true,
},
},
},
safeql.configs.connections({
connections: [
{
migrationsDir: "./migrations",
targets: [
// Check all of the queries that matches db.sql`...`
{ tag: "db.sql" },
],
// To connect using alternate superuser credentials, see below
// "connectionUrl": "postgres://pguser:password@localhost:5432/postgres"
},
],
})
);