Documentation ¶
Overview ¶
Package gondolier is a library to auto migrate database schemas for Go using structs.
Quick example:
TODO
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Drop ¶
func Drop(models ...interface{})
Drop drops tables for given objects if they exist. The database connection and migrator must be set before by calling Use(). The objects can be passed as references, values or mixed. This function might panic if an invalid model is used or the tables cannot be dropped.
Example:
Drop(&MyModel{}, AnotherModel{})
func Migrate ¶
func Migrate()
Migrate migrates models added previously using Model(). The database connection and migrator must be set before by calling Use().
Example:
Use(Postgres) Model(MyModel{}, AnotherModel{}) Migrate()
func Model ¶
func Model(models ...interface{})
Model adds one or more objects for migration. The objects can be passed as references, values or mixed. This function might panic if an invalid model is used.
Example:
Model(&MyModel{}, AnotherModel{})
func Naming ¶
func Naming(schema NameSchema)
Naming sets the naming pattern used for migration. Default is snake case.
Example:
Naming(SnakeCase)
Types ¶
type NameSchema ¶
NameSchema interface used to translate model names to schema names.
type Postgres ¶
type Postgres struct { Schema string DropColumns bool Log bool // contains filtered or unexported fields }
Postgres migrator for Postgres databases. You can use the following options to configure your data model:
// The type must be the database type. type:database type // Sets the column as primary key. pk/primary key // Creates and sets a sequence with given parameters for the column. seq:start,increment,minvalue,maxvalue,cache // Sets the default value for column, strings must be escaped. // next(seq) refers to the sequences assign for this column (using seq:...). default:default value/next(seq) // Sets not null constraint for column. not null/notnull // Optional. Drops not null constraint if set for column. Not null is also dropped if not null is not set. null // Sets unique constraint for column. unique // Shortcut for primary key, not null, seq:1,1,-,-,1 and default:next(seq). id // Sets foreign key constraint for column. // It refers to the given model and column. // Example: fk:MyModel.Id fk/foreign key:Model.Column