How to use node-pg-migrate - 8 common examples

To help you get started, we’ve selected a few node-pg-migrate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adrach / starter-postgres-express-react / scripts / db-migrate.js View on Github external
function main() {
  // Execute the migrations
  console.log("Running the migrations...");
  return migrate.default({
    databaseUrl,
    migrationsTable,
    migrationsSchema,
    schema,
    direction,
    dir
  });
}
github cardstack / cardstack / packages / pgsearch / client.js View on Github external
async _migrateDb() {
    let client = new Client(Object.assign({}, config, { database: 'postgres' }));
    try {
      await client.connect();
      let response = await client.query(`select count(*)=1 as has_database from pg_database where datname=$1`, [
        config.database,
      ]);
      if (!response.rows[0].has_database) {
        await client.query(`create database ${safeDatabaseName(config.database)}`);
      }
    } finally {
      client.end();
    }

    await migrate({
      direction: 'up',
      migrationsTable: 'migrations',
      singleTransaction: true,
      checkOrder: false,
      databaseUrl: {
        user: config.user,
        host: config.host,
        database: config.database,
        password: config.password,
        port: config.port,
      },
      dir: join(__dirname, 'migrations'),
      log: (...args) => log.debug(...args),
    });
  }
github cardstack / cardstack / packages / postgresql / indexer.js View on Github external
async _runMigrations() {
    let config = this.config;
    if (!config.migrationsDir) {
      return;
    }
    let dir = path.join(this.projectPath, config.migrationsDir);

    await migrate({
      direction: 'up',
      migrationsTable: 'migrations',
      singleTransaction: true,
      checkOrder: false,
      databaseUrl: {
        user: config.user,
        host: config.host,
        database: config.database,
        password: config.password,
        port: config.port
      },
      dir,
      log: (...args) => log.debug(...args)
    });
  }
});
github cardstack / cardstack / packages / ethereum / cardstack / transaction-index-base.js View on Github external
async _migrateDb() {
    let client = new Client(Object.assign({}, config, { database: 'postgres' }));
    try {
      await client.connect();
      let response = await client.query(`select count(*)=1 as has_database from pg_database where datname=$1`, [config.database]);
      if (!response.rows[0].has_database) {
        await client.query(`create database ${this.safeDatabaseName(config.database)}`);
      }
    } finally {
      client.end();
    }

    await migrate({
      direction: 'up',
      migrationsTable: 'migrations',
      singleTransaction: true,
      checkOrder: false,
      databaseUrl: {
        user: config.user,
        host: config.host,
        database: config.database,
        password: config.password,
        port: config.port
      },
      dir: join(__dirname, 'migrations'),
      log: (...args) => log.debug(...args)
    });
  }
github cardstack / cardstack / packages / ethereum / cardstack / transaction-index.js View on Github external
async _migrateDb() {
    let client = new Client(Object.assign({}, config, { database: 'postgres' }));
    try {
      await client.connect();
      let response = await client.query(`select count(*)=1 as has_database from pg_database where datname=$1`, [config.database]);
      if (!response.rows[0].has_database) {
        await client.query(`create database ${safeDatabaseName(config.database)}`);
      }
    } finally {
      client.end();
    }

    await migrate({
      direction: 'up',
      migrationsTable: 'migrations',
      singleTransaction: true,
      checkOrder: false,
      databaseUrl: {
        user: config.user,
        host: config.host,
        database: config.database,
        password: config.password,
        port: config.port
      },
      dir: join(__dirname, 'migrations'),
      log: (...args) => log.debug(...args)
    });
  }
github cardstack / cardstack / packages / hub / pgsearch / pgclient.ts View on Github external
private async migrateDb() {
    const config = postgresConfig();
    let client = new Client(Object.assign({}, config, { database: 'postgres' }));
    try {
      await client.connect();
      let response = await client.query(`select count(*)=1 as has_database from pg_database where datname=$1`, [
        config.database,
      ]);
      if (!response.rows[0].has_database) {
        await client.query(`create database ${safeName(config.database)}`);
      }
    } finally {
      client.end();
    }

    await migrate({
      direction: 'up',
      migrationsTable: 'migrations',
      singleTransaction: true,
      checkOrder: false,
      databaseUrl: {
        user: config.user,
        host: config.host,
        database: config.database,
        password: config.password,
        port: config.port,
      },
      count: Infinity,
      ignorePattern: '.*\\.(?!js)[^.]+',
      dir: join(__dirname, 'migrations'),
      log: (...args) => log.debug(...args),
    });
github nasa / earthdata-search / serverless / src / migrateDatabase / handler.js View on Github external
const migrateDatabase = async (event) => {
  try {
    const dbConnectionConfig = await getDbConnectionConfig()

    const dbClient = new Client(dbConnectionConfig)

    await dbClient.connect()

    const config = {
      dbClient,
      direction: event.direction || 'up',
      dir: 'migrations',
      migrationsTable: 'pgmigrations'
    }

    const migrationResponse = await pgMigrate(config)

    await dbClient.end()

    if (migrationResponse.length) {
      return {
        isBase64Encoded: false,
        statusCode: 200,
        body: JSON.stringify(migrationResponse)
      }
    }

    return {
      isBase64Encoded: false,
      statusCode: 200,
      body: JSON.stringify({ message: 'No migrations to run!' })
    }
github nasa / earthdata-search / serverless / src / migrateDatabase / handler.js View on Github external
try {
    dbConnectionConfig = await getDbConnectionConfig(dbConnectionConfig)
    dbConnectionConfig.database = 'uat-import-test'

    const dbClient = new Client(dbConnectionConfig)

    await dbClient.connect()

    const config = {
      dbClient,
      direction: event.direction || 'up',
      dir: 'migrations',
      migrationsTable: 'pgmigrations'
    }

    const migrationResponse = await pgMigrate(config)

    await dbClient.end()

    if (migrationResponse.length) {
      return {
        isBase64Encoded: false,
        statusCode: 200,
        body: JSON.stringify(migrationResponse)
      }
    }

    return {
      isBase64Encoded: false,
      statusCode: 200,
      body: JSON.stringify({ message: 'No migrations to run!' })
    }

node-pg-migrate

PostgreSQL database migration management tool for node.js

MIT
Latest version published 25 days ago

Package Health Score

84 / 100
Full package analysis

Popular node-pg-migrate functions