migrate

package
v0.0.0-...-444ad2e Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// WithGlobalUniqueID sets the universal ids options to the migration.
	// If this option is enabled, ent migration will allocate a 1<<32 range
	// for the ids of each entity (table).
	// Note that this option cannot be applied on tables that already exist.
	WithGlobalUniqueID = schema.WithGlobalUniqueID
	// WithDropColumn sets the drop column option to the migration.
	// If this option is enabled, ent migration will drop old columns
	// that were used for both fields and edges. This defaults to false.
	WithDropColumn = schema.WithDropColumn
	// WithDropIndex sets the drop index option to the migration.
	// If this option is enabled, ent migration will drop old indexes
	// that were defined in the schema. This defaults to false.
	// Note that unique constraints are defined using `UNIQUE INDEX`,
	// and therefore, it's recommended to enable this option to get more
	// flexibility in the schema changes.
	WithDropIndex = schema.WithDropIndex
	// WithFixture sets the foreign-key renaming option to the migration when upgrading
	// ent from v0.1.0 (issue-#285). Defaults to true.
	WithFixture = schema.WithFixture
)
View Source
var (
	// AccountsColumns holds the columns for the "accounts" table.
	AccountsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "type", Type: field.TypeEnum, Enums: []string{"Google", "Anonymous", "Email"}},
		{Name: "sub", Type: field.TypeString},
		{Name: "remote_id", Type: field.TypeString, Unique: true},
		{Name: "secret", Type: field.TypeString, Nullable: true},
		{Name: "person_accounts", Type: field.TypeUUID, Nullable: true},
	}
	// AccountsTable holds the schema information for the "accounts" table.
	AccountsTable = &schema.Table{
		Name:       "accounts",
		Columns:    AccountsColumns,
		PrimaryKey: []*schema.Column{AccountsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "accounts_persons_accounts",
				Columns: []*schema.Column{AccountsColumns[5]},

				RefColumns: []*schema.Column{PersonsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// AnswersColumns holds the columns for the "answers" table.
	AnswersColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "at", Type: field.TypeTime},
		{Name: "responses", Type: field.TypeJSON},
		{Name: "valid", Type: field.TypeBool, Nullable: true},
		{Name: "question_answers", Type: field.TypeUUID, Nullable: true},
	}
	// AnswersTable holds the schema information for the "answers" table.
	AnswersTable = &schema.Table{
		Name:       "answers",
		Columns:    AnswersColumns,
		PrimaryKey: []*schema.Column{AnswersColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "answers_questions_answers",
				Columns: []*schema.Column{AnswersColumns[4]},

				RefColumns: []*schema.Column{QuestionsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// ContactsColumns holds the columns for the "contacts" table.
	ContactsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "name", Type: field.TypeString},
		{Name: "value", Type: field.TypeString},
		{Name: "kind", Type: field.TypeEnum, Enums: []string{"Email", "Phone"}, Default: "Email"},
		{Name: "principal", Type: field.TypeBool},
		{Name: "validated", Type: field.TypeBool},
		{Name: "from_account", Type: field.TypeBool},
		{Name: "person_contacts", Type: field.TypeUUID, Nullable: true},
	}
	// ContactsTable holds the schema information for the "contacts" table.
	ContactsTable = &schema.Table{
		Name:       "contacts",
		Columns:    ContactsColumns,
		PrimaryKey: []*schema.Column{ContactsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "contacts_persons_contacts",
				Columns: []*schema.Column{ContactsColumns[7]},

				RefColumns: []*schema.Column{PersonsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// DevicesColumns holds the columns for the "devices" table.
	DevicesColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "device", Type: field.TypeString},
	}
	// DevicesTable holds the schema information for the "devices" table.
	DevicesTable = &schema.Table{
		Name:        "devices",
		Columns:     DevicesColumns,
		PrimaryKey:  []*schema.Column{DevicesColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// DomainsColumns holds the columns for the "domains" table.
	DomainsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "name", Type: field.TypeString},
		{Name: "email", Type: field.TypeString, Unique: true},
		{Name: "domain", Type: field.TypeString, Unique: true},
		{Name: "callback", Type: field.TypeString},
		{Name: "tags", Type: field.TypeJSON},
	}
	// DomainsTable holds the schema information for the "domains" table.
	DomainsTable = &schema.Table{
		Name:        "domains",
		Columns:     DomainsColumns,
		PrimaryKey:  []*schema.Column{DomainsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// FlowsColumns holds the columns for the "flows" table.
	FlowsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "state", Type: field.TypeUUID},
		{Name: "state_table", Type: field.TypeString},
		{Name: "initial_state", Type: field.TypeUUID},
		{Name: "termination_state", Type: field.TypeUUID},
		{Name: "past_state", Type: field.TypeUUID, Nullable: true},
		{Name: "inputs", Type: field.TypeJSON, Nullable: true},
		{Name: "survey_flow", Type: field.TypeUUID, Unique: true, Nullable: true},
	}
	// FlowsTable holds the schema information for the "flows" table.
	FlowsTable = &schema.Table{
		Name:       "flows",
		Columns:    FlowsColumns,
		PrimaryKey: []*schema.Column{FlowsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "flows_surveys_flow",
				Columns: []*schema.Column{FlowsColumns[7]},

				RefColumns: []*schema.Column{SurveysColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// IPsColumns holds the columns for the "i_ps" table.
	IPsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "ip", Type: field.TypeString},
	}
	// IPsTable holds the schema information for the "i_ps" table.
	IPsTable = &schema.Table{
		Name:        "i_ps",
		Columns:     IPsColumns,
		PrimaryKey:  []*schema.Column{IPsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// InputsColumns holds the columns for the "inputs" table.
	InputsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "kind", Type: field.TypeEnum, Enums: []string{"Text", "Options", "Satisfaction", "Boolean"}},
		{Name: "multiple", Type: field.TypeBool, Nullable: true},
		{Name: "defaults", Type: field.TypeJSON, Nullable: true},
		{Name: "options", Type: field.TypeJSON, Nullable: true},
		{Name: "question_input", Type: field.TypeUUID, Unique: true, Nullable: true},
	}
	// InputsTable holds the schema information for the "inputs" table.
	InputsTable = &schema.Table{
		Name:       "inputs",
		Columns:    InputsColumns,
		PrimaryKey: []*schema.Column{InputsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "inputs_questions_input",
				Columns: []*schema.Column{InputsColumns[5]},

				RefColumns: []*schema.Column{QuestionsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// PersonsColumns holds the columns for the "persons" table.
	PersonsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "name", Type: field.TypeString},
		{Name: "last_activity", Type: field.TypeTime},
		{Name: "username", Type: field.TypeString, Nullable: true},
		{Name: "picture", Type: field.TypeString, Nullable: true},
		{Name: "roles", Type: field.TypeJSON, Nullable: true},
	}
	// PersonsTable holds the schema information for the "persons" table.
	PersonsTable = &schema.Table{
		Name:        "persons",
		Columns:     PersonsColumns,
		PrimaryKey:  []*schema.Column{PersonsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// QuestionsColumns holds the columns for the "questions" table.
	QuestionsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "hash", Type: field.TypeString},
		{Name: "title", Type: field.TypeString},
		{Name: "description", Type: field.TypeString},
		{Name: "metadata", Type: field.TypeJSON, Nullable: true},
		{Name: "validator", Type: field.TypeString, Nullable: true},
		{Name: "anonymous", Type: field.TypeBool},
		{Name: "flow_questions", Type: field.TypeUUID, Nullable: true},
	}
	// QuestionsTable holds the schema information for the "questions" table.
	QuestionsTable = &schema.Table{
		Name:       "questions",
		Columns:    QuestionsColumns,
		PrimaryKey: []*schema.Column{QuestionsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "questions_flows_questions",
				Columns: []*schema.Column{QuestionsColumns[7]},

				RefColumns: []*schema.Column{FlowsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// ShortsColumns holds the columns for the "shorts" table.
	ShortsColumns = []*schema.Column{
		{Name: "id", Type: field.TypeInt, Increment: true},
		{Name: "key", Type: field.TypeString, Unique: true},
		{Name: "value", Type: field.TypeUUID},
	}
	// ShortsTable holds the schema information for the "shorts" table.
	ShortsTable = &schema.Table{
		Name:        "shorts",
		Columns:     ShortsColumns,
		PrimaryKey:  []*schema.Column{ShortsColumns[0]},
		ForeignKeys: []*schema.ForeignKey{},
	}
	// SurveysColumns holds the columns for the "surveys" table.
	SurveysColumns = []*schema.Column{
		{Name: "id", Type: field.TypeUUID},
		{Name: "tags", Type: field.TypeJSON},
		{Name: "last_interaction", Type: field.TypeTime},
		{Name: "due_date", Type: field.TypeTime},
		{Name: "title", Type: field.TypeString},
		{Name: "description", Type: field.TypeString, Nullable: true},
		{Name: "metadata", Type: field.TypeJSON, Nullable: true},
		{Name: "done", Type: field.TypeBool, Nullable: true},
		{Name: "is_public", Type: field.TypeBool, Nullable: true},
		{Name: "domain_surveys", Type: field.TypeUUID, Nullable: true},
		{Name: "person_surveys", Type: field.TypeUUID, Nullable: true},
	}
	// SurveysTable holds the schema information for the "surveys" table.
	SurveysTable = &schema.Table{
		Name:       "surveys",
		Columns:    SurveysColumns,
		PrimaryKey: []*schema.Column{SurveysColumns[0]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "surveys_domains_surveys",
				Columns: []*schema.Column{SurveysColumns[9]},

				RefColumns: []*schema.Column{DomainsColumns[0]},
				OnDelete:   schema.SetNull,
			},
			{
				Symbol:  "surveys_persons_surveys",
				Columns: []*schema.Column{SurveysColumns[10]},

				RefColumns: []*schema.Column{PersonsColumns[0]},
				OnDelete:   schema.SetNull,
			},
		},
	}
	// DomainUsersColumns holds the columns for the "domain_users" table.
	DomainUsersColumns = []*schema.Column{
		{Name: "domain_id", Type: field.TypeUUID},
		{Name: "person_id", Type: field.TypeUUID},
	}
	// DomainUsersTable holds the schema information for the "domain_users" table.
	DomainUsersTable = &schema.Table{
		Name:       "domain_users",
		Columns:    DomainUsersColumns,
		PrimaryKey: []*schema.Column{DomainUsersColumns[0], DomainUsersColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "domain_users_domain_id",
				Columns: []*schema.Column{DomainUsersColumns[0]},

				RefColumns: []*schema.Column{DomainsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:  "domain_users_person_id",
				Columns: []*schema.Column{DomainUsersColumns[1]},

				RefColumns: []*schema.Column{PersonsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// DomainAdminsColumns holds the columns for the "domain_admins" table.
	DomainAdminsColumns = []*schema.Column{
		{Name: "domain_id", Type: field.TypeUUID},
		{Name: "person_id", Type: field.TypeUUID},
	}
	// DomainAdminsTable holds the schema information for the "domain_admins" table.
	DomainAdminsTable = &schema.Table{
		Name:       "domain_admins",
		Columns:    DomainAdminsColumns,
		PrimaryKey: []*schema.Column{DomainAdminsColumns[0], DomainAdminsColumns[1]},
		ForeignKeys: []*schema.ForeignKey{
			{
				Symbol:  "domain_admins_domain_id",
				Columns: []*schema.Column{DomainAdminsColumns[0]},

				RefColumns: []*schema.Column{DomainsColumns[0]},
				OnDelete:   schema.Cascade,
			},
			{
				Symbol:  "domain_admins_person_id",
				Columns: []*schema.Column{DomainAdminsColumns[1]},

				RefColumns: []*schema.Column{PersonsColumns[0]},
				OnDelete:   schema.Cascade,
			},
		},
	}
	// Tables holds all the tables in the schema.
	Tables = []*schema.Table{
		AccountsTable,
		AnswersTable,
		ContactsTable,
		DevicesTable,
		DomainsTable,
		FlowsTable,
		IPsTable,
		InputsTable,
		PersonsTable,
		QuestionsTable,
		ShortsTable,
		SurveysTable,
		DomainUsersTable,
		DomainAdminsTable,
	}
)

Functions

This section is empty.

Types

type Schema

type Schema struct {
	// contains filtered or unexported fields
}

Schema is the API for creating, migrating and dropping a schema.

func NewSchema

func NewSchema(drv dialect.Driver) *Schema

NewSchema creates a new schema client.

func (*Schema) Create

func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error

Create creates all schema resources.

func (*Schema) WriteTo

func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error

WriteTo writes the schema changes to w instead of running them against the database.

if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
	log.Fatal(err)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL