Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ jobs:
- name: build
run: yarn build

- name: seed app_user
run: |
psql -f ./bootstrap-roles.sql postgres
env:
PGHOST: pg_db
PGPORT: 5432
PGUSER: postgres
PGPASSWORD: password

- name: launchql/migrate
run: cd ./packages/migrate && yarn test

Expand All @@ -72,6 +81,17 @@ jobs:
yarn test
env:
PGHOST: pg_db
PGPORT: 5432
PGUSER: postgres
PGPASSWORD: password

- name: pgsql-test
run: |
cd ./packages/pgsql-test
yarn test
env:
PGHOST: pg_db
PGPORT: 5432
PGUSER: postgres
PGPASSWORD: password

Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import plan from './commands/plan';
import _export from './commands/export';
import _package from './commands/package';
import kill from './commands/kill';
import { teardownPgPools } from '@launchql/server-utils';

// Command map
const commandMap: Record<string, Function> = {
Expand Down Expand Up @@ -82,5 +83,7 @@ export const commands = async (argv: Partial<ParsedArgs>, prompter: Inquirerer,

await commandFn(newArgv, prompter, options);
prompter.close();

await teardownPgPools();
return argv;
};
4 changes: 0 additions & 4 deletions packages/cli/src/commands/export.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { CLIOptions, Inquirerer, OptionValue } from 'inquirerer';
import { LaunchQLProject, exportMigrations } from '@launchql/migrate';
import { getEnvOptions } from '@launchql/types';
import chalk from 'chalk';
import { resolve } from 'path';
import { execSync } from 'child_process';
import { getRootPgPool } from '@launchql/server-utils';
Expand All @@ -20,10 +19,8 @@ export default async (
project.ensureWorkspace();

const options = getEnvOptions();
const { pg } = options;

const db = await getRootPgPool({
...pg,
database: 'postgres'
});

Expand All @@ -46,7 +43,6 @@ export default async (

const dbname = databases.filter(d=>d.selected).map(d=>d.value)[0];
const selectedDb = await getRootPgPool({
...pg,
database: dbname
});

Expand Down
4 changes: 0 additions & 4 deletions packages/cli/src/commands/kill.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CLIOptions, Inquirerer, OptionValue } from 'inquirerer';
import { getEnvOptions } from '@launchql/types';
import { getRootPgPool } from '@launchql/server-utils';
import chalk from 'chalk';

Expand All @@ -8,11 +7,8 @@ export default async (
prompter: Inquirerer,
_options: CLIOptions
) => {
const options = getEnvOptions();
const { pg } = options;

const db = await getRootPgPool({
...pg,
database: 'postgres'
});

Expand Down
48 changes: 29 additions & 19 deletions packages/explorer/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {
} from '@launchql/server-utils';
import { printSchemas, printDatabases } from './render';
import { getGraphileSettings } from './settings';
import { LaunchQLOptions } from '@launchql/types';
import { getMergedOptions } from '@launchql/types';
import { getPgEnvOptions, LaunchQLOptions } from '@launchql/types';
import { getEnvOptions } from '@launchql/types';

export const LaunchQLExplorer = (rawOpts: LaunchQLOptions = {}): Express => {
const opts = getMergedOptions(rawOpts);
const opts = getEnvOptions(rawOpts);

const {
pg,
Expand All @@ -39,10 +39,12 @@ export const LaunchQLExplorer = (rawOpts: LaunchQLOptions = {}): Express => {
graphiqlRoute: '/graphiql'
};

const pgPool = getRootPgPool({
...opts.pg,
database: dbname
});
const pgPool = getRootPgPool(
getPgEnvOptions({
...opts.pg,
database: dbname
}));

const handler = postgraphile(pgPool, schemaname, settings);

const obj = {
Expand All @@ -67,10 +69,12 @@ export const LaunchQLExplorer = (rawOpts: LaunchQLOptions = {}): Express => {
if (req.urlDomains?.subdomains.length === 1) {
const [dbName] = req.urlDomains.subdomains;
try {
const pgPool = getRootPgPool({
...opts.pg,
database: dbName
});
const pgPool = getRootPgPool(
getPgEnvOptions({
...opts.pg,
database: dbName
}));

const results = await pgPool.query(`
SELECT s.nspname AS table_schema
FROM pg_catalog.pg_namespace s
Expand Down Expand Up @@ -103,11 +107,15 @@ export const LaunchQLExplorer = (rawOpts: LaunchQLOptions = {}): Express => {
if (req.urlDomains?.subdomains.length === 2) {
const [, dbName] = req.urlDomains.subdomains;
try {
const pgPool = getRootPgPool({
...opts.pg,
database: dbName
});

const pgPool = getRootPgPool(
getPgEnvOptions({
...opts.pg,
database: dbName
}));

await pgPool.query('SELECT 1;');

} catch (e: any) {
if (e.message?.match(/does not exist/)) {
res.status(404).send('DB Not found');
Expand Down Expand Up @@ -150,10 +158,12 @@ export const LaunchQLExplorer = (rawOpts: LaunchQLOptions = {}): Express => {
app.use(async (req: Request, res: Response, next: NextFunction) => {
if (req.urlDomains?.subdomains.length === 0) {
try {
const rootPgPool = getRootPgPool({
...opts.pg,
database: opts.pg.user // is this to get postgres?
});
const rootPgPool = getRootPgPool(
getPgEnvOptions({
...opts.pg,
database: opts.pg.user // is this to get postgres?
}));

const results = await rootPgPool.query(`
SELECT * FROM pg_catalog.pg_database
WHERE datistemplate = FALSE AND datname != 'postgres' AND datname !~ '^pg_'
Expand Down
4 changes: 2 additions & 2 deletions packages/explorer/src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { PostGraphileOptions } from 'postgraphile';
import { getGraphileSettings as getSettings } from '@launchql/graphile-settings';
import { LaunchQLOptions } from '@launchql/types';
import { getMergedOptions } from '@launchql/types';
import { getEnvOptions } from '@launchql/types';

export const getGraphileSettings = (rawOpts: LaunchQLOptions): PostGraphileOptions => {
const opts = getMergedOptions(rawOpts);
const opts = getEnvOptions(rawOpts);

const baseOptions = getSettings(opts);

Expand Down
1 change: 0 additions & 1 deletion packages/graphile-settings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"@pyramation/postgis": "^0.1.1",
"@pyramation/postgraphile-plugin-fulltext-filter": "^2.0.0",
"cors": "^2.8.5",
"envalid": "^8.0.0",
"express": "^5.1.0",
"graphile-build": "^4.14.1",
"graphile-i18n": "^0.0.3",
Expand Down
4 changes: 2 additions & 2 deletions packages/graphile-settings/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import LqlTypesPlugin from './plugins/types';
import { Uploader } from './resolvers/upload';
import { PostGraphileOptions } from 'postgraphile';
import { LaunchQLOptions } from '@launchql/types';
import { getMergedOptions } from '@launchql/types';
import { getEnvOptions } from '@launchql/types';

export const getGraphileSettings = (rawOpts: LaunchQLOptions): PostGraphileOptions => {
const opts = getMergedOptions(rawOpts);
const opts = getEnvOptions(rawOpts);

const {
server,
Expand Down
6 changes: 3 additions & 3 deletions packages/migrate/src/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolve } from 'path';
import chalk from 'chalk';

import { LaunchQLOptions } from '@launchql/types';
import { getSpawnEnvWithPg, LaunchQLOptions } from '@launchql/types';
import { getRootPgPool } from '@launchql/server-utils';
import { LaunchQLProject } from './class/launchql';
import { spawn } from 'child_process';
Expand Down Expand Up @@ -53,7 +53,7 @@ export const deploy = async (

const child = spawn('sqitch', ['deploy', `db:pg:${database}`], {
cwd: modulePath,
env: { ...process.env }
env: getSpawnEnvWithPg(opts.pg)
});

const exitCode: number = await new Promise((resolve, reject) => {
Expand Down Expand Up @@ -91,6 +91,6 @@ export const deploy = async (
}

console.log(chalk.green(`\n✅ Deployment complete for ${chalk.bold(name)}.\n`));
await pgPool.end();
// await pgPool.end();
return extensions;
};
Loading