spannerdiff

package module
v0.0.0-...-7653a68 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2025 License: MIT Imports: 17 Imported by: 0

README

spannerdiff

Schema migration tool for Cloud Spanner.

Note: This tool is currently under development. The interface may change.

Installation

$ brew install morikuni/tap/spannerdiff 

Supported DDL

  • CREATE SCHEMA
  • CREATE TABLE
  • CREATE INDEX
  • CREATE SEARCH INDEX
  • CREATE PROPERTY GRAPH
  • CREATE VIEW
  • CREATE CHANGE STREAM
  • CREATE SEQUENCE
  • CREATE VECTOR INDEX
  • CREATE MODEL
  • CREATE PROTO BUNDLE
  • CREATE ROLE
  • GRANT
  • ALTER DATABASE

Colored Output

colored output

Example

$ gcloud spanner databases ddl describe test
CREATE TABLE Test (
    ID STRING(64) NOT NULL,
    Name STRING(64) NOT NULL,
) PRIMARY KEY (ID);

CREATE INDEX Test_Name ON Test (Name);
$ cat schema.sql
CREATE TABLE Test (
    ID STRING(64) NOT NULL,
    Name STRING(64) NOT NULL,
    CreatedAt TIMESTAMP NOT NULL DEFAULT (CURRENT_TIMESTAMP()),
) PRIMARY KEY (ID);

CREATE INDEX Test_Name_CreatedAt ON Test (Name, CreatedAt DESC);
$ gcloud spanner databases ddl describe test | spannerdiff --base-stdin --target-file=schema.sql | tee tmp.sql
DROP INDEX Test_Name;

ALTER TABLE Test ADD COLUMN CreatedAt TIMESTAMP NOT NULL DEFAULT (CURRENT_TIMESTAMP());

CREATE INDEX Test_Name_CreatedAt ON Test(Name, CreatedAt DESC);
$ gcloud spanner databases ddl update test --ddl-file=tmp.sql
Schema updating...done.

Known Issues & Limitations

  • View DDL generation may be incorrect or out of order due to unresolved column names in the view query.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(baseSQL, targetSQL io.Reader, output io.Writer, option DiffOption) error

Types

type ColorMode

type ColorMode string
const (
	ColorAuto   ColorMode = "auto"
	ColorAlways ColorMode = "always"
	ColorNever  ColorMode = "never"
)

func NewColorMode

func NewColorMode(s string) (ColorMode, bool)

type DiffOption

type DiffOption struct {
	ErrorOnUnsupportedDDL bool
	Printer               Printer
}

type NoStylePrinter

type NoStylePrinter struct{}

func (NoStylePrinter) Print

func (NoStylePrinter) Print(ctx PrintContext, out io.Writer, sql string) error

type PrintContext

type PrintContext struct {
	Index     int
	TotalSQLs int
}

type Printer

type Printer interface {
	Print(ctx PrintContext, out io.Writer, sql string) error
}

func DetectTerminalPrinter

func DetectTerminalPrinter(mode ColorMode, stdout *os.File) Printer

func NewColorTerminalPrinter

func NewColorTerminalPrinter() Printer

func WithSpacer

func WithSpacer(spacer string, p Printer) Printer

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳