0.49.38 • Published 1 year ago

@triptease/terra-ratchet-big-query v0.49.38

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

TerraRatchet

<Triptease> npm version

Migrate your environments with real code today!

Why?

  • Have you ever wanted to write real code instead of declarative configuration files?
  • Have you ever wanted to use a migration tool for something other than a DB?
  • Have you ever wanted to run a single command just once against each environment?
  • Have you ever waited for a plugin to be upgraded to use a new feature that was just released?

If the answer to any of those question is yes then TerraRatchet may be what you have been waiting for.

How?

If you have used a DB migration tool recently you probably already know how to use TerraRatchet, you have a folder with a bunch of scripts that need to be run once in a certain order (these are normally checked in):

scripts
  001-deploy-postgres.sh
  002-create-database.postgres.sql
  003-create-bigquery-dataset.sh
  004-add-permissions-to-dataset.sh
  005-import-table.bigquery.sql
  006-create-redis-server.sh
  007-create-timeseries.redis

You have a DB or file server than can store which scripts have been run, normally part of the environment you are deploying.

Now just add TerraRatchet to your build.

Example (ratchet.ts)

import { TerraRatchet, FileRunnableScripts, NoOpScriptRunner, ShellScriptRunner } from '@triptease/terra-ratchet';
import { BigQueryExecutedScripts, BigQueryScriptRunner } from '@triptease/terra-ratchet-big-query';

const projectId = process.env.GOOGLE_CLOUD_PROJECT;
const datasetId = process.env.CI === 'true' ? 'production' : 'development';
const tableId = 'ratchet-table-id';

(async () => {
    const env = { ...process.env, projectId, datasetId };
    const executedScripts = new BigQueryExecutedScripts(projectId, datasetId, tableId);

    const directory = 'scripts';

    await new TerraRatchet(new FileRunnableScripts(directory), executedScripts)
        .ignore('d.ts', 'js', 'map') // ignore generated code
        .register('006-create-redis-server.sh', new NoOpScriptRunner()) // skip manually ran script
        .register('sql', new BigQueryScriptRunner(directory, projectId, datasetId))
        .register('sh', new ShellScriptRunner(directory, env))
        .run();
})();

Details

TerraRatchet is made up of a couple of different parts:

Script location (RunnableScripts)

RunnableScriptsStatusDescription
InMemoryRunnableScriptsReleasedCan be used for testing
FileRunnableScriptsReleasedPoint to a folder

Record which script have been run (ExecutedScripts)

ExecutedScriptsStatusDescription
InMemoryExecutedScriptsReleasedCan be used for testing
FileExecutedScriptsReleasedRecords which scripts have been run in a json file
BigQueryExecutedScriptsReleasedRecords which scripts have been run in a BigQuery table
PostgresExecutedScriptsPlannedRecords which scripts have been run in a Postgres table

How each script should run (ScriptRunner)

It's worth remember than any command can be run if it has a command line, the SQL runners are just convenient

ScriptRunnerStatusDescription
NoOpScriptRunnerReleasedDoes nothing. Can be used to ignore a manually run script
ShellScriptRunnerReleasedUsed to run a shell command (anything, no plugins required)
BigQueryScriptRunnerReleasedUsed to run BigQuery SQL statements
PostgresScriptRunnerPlannedUsed to run Postgres SQL statements
0.49.38

1 year ago

0.48.37

1 year ago

0.45.34

2 years ago

0.47.36

2 years ago

0.46.35

2 years ago

0.44.33

2 years ago

0.43.32

2 years ago

0.42.31

2 years ago

0.41.30

2 years ago