npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

google-spanner-migrations-runner

v1.10.0

Published

Migrations runner for Google Cloud Spanner Database

Downloads

1,858

Readme

Google Spanner Migrations Runner

Deploy

What is this?

This tool will take care of automatic schema managing in your Spanner database (both Google-managed and emulator). This is basically an engine for running migrations. The burden of writing & testing migrations (sql scripts) is on you. This engine does not generate schema from your code.

What it can do:

  • run your migrations (from .sql files)
  • keep track of migrations, to not reapply already processed.

How it works

Algorithm:

  1. Goes though migrations directory
  2. Fetches all *.sql files
  3. Validates them
  4. Applies them in order, that they are in directory (in transaction), so naming matters

Usage

Requirements

To run tool, you need to have nodejs 14+ version installed

Create your migrations

To add migrations, just add *.sql file with migration to migrations directory.

Each statement must be separated with ;, engine will rely on this to run each query separately.

Example of valid migration:

CREATE TABLE test (
  id          INT64 NOT NULL,
) PRIMARY KEY (id);
ALTER TABLE test ADD COLUMN newcol BYTES(100);

IMPORTANT each migration MUST include only one type of statements. Available types:

  • Create/modify tables
  • Other SQL queries

Must follow pattern - [0-9]{5}[a-z\-]{0,256}.sql. Once migration is applied name MUST NOT be changed, as engine relies on name to figure out if migration already applied. Also do not modify already applied migrations (only if you absolutely sure)

Migrations will be applied in the same order as files in directory.

Examples of valid and invalid migrations can be found here

What happens if I run migration twice?

Engine stores applied migrations in special table (managed automatically) and just skips already applied migrations.

Run migrations

From shell

# via npx
npx google-spanner-migrations-runner --project-id --instance-id=test --database-id=test

# or install globally
npm i -g google-spanner-migrations-runner
google-spanner-migrations-runner --project-id --instance-id=test --database-id=test

Also cli configuration is available by env variables (automatically loaded from env) Note: if you have .env file where you run this cli, it will load variables and use them. Actual env variables you can check via:

npx google-spanner-migrations-runner --help

From code

import { SpannerMigration } from 'google-spanner-migrations-runner';

async function run() {
  const config = {
    /* your config */
  };
  const runner = new SpannerMigration(config);

  await runner.runMigrations();
}

run();

Emulator limitations

Some features are not available on emulator, so runner will ignore & log ignored statements on emulator.

Features ignored:

  • adding row deletion policy
  • creating, replacing or dropping views
  • creating and dropping roles
  • granting or revoking permissions to existing roles

Contributing

If you want to contribute to this repo, or just run it locally, you can use Spanner emulator:

docker compose up -d

and run tool with ts-node using samples:

ts-node src/cli.ts -mr test/samples/valid/single

Licence

Bootstrapped with: create-ts-lib-gh

This project is Mit Licensed.