Files
upstream-ent/examples/migration/ent/migrate/schema.go
upstream-mirror 4b3ad0b611
Some checks failed
Atlas CI Public / lint (push) Failing after 13s
Atlas CI Public / sync (push) Has been skipped
snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
2026-09-15 22:12:36 +05:00

214 lines
7.2 KiB
Go

// Copyright 2019-present Facebook Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
// Code generated by ent, DO NOT EDIT.
package migrate
import (
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/dialect/sql/schema"
"entgo.io/ent/schema/field"
)
var (
// CardsColumns holds the columns for the "cards" table.
CardsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "type", Type: field.TypeString, Default: "unknown"},
{Name: "number_hash", Type: field.TypeString},
{Name: "cvv_hash", Type: field.TypeString},
{Name: "expires_at", Type: field.TypeTime, Nullable: true},
{Name: "owner_id", Type: field.TypeInt, Default: 0},
}
// CardsTable holds the schema information for the "cards" table.
CardsTable = &schema.Table{
Name: "cards",
Columns: CardsColumns,
PrimaryKey: []*schema.Column{CardsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "cards_users_cards",
Columns: []*schema.Column{CardsColumns[5]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.NoAction,
},
},
}
// PaymentsColumns holds the columns for the "payments" table.
PaymentsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "amount", Type: field.TypeFloat64},
{Name: "currency", Type: field.TypeEnum, Enums: []string{"USD", "EUR", "VND", "ILS"}},
{Name: "time", Type: field.TypeTime},
{Name: "description", Type: field.TypeString},
{Name: "status", Type: field.TypeEnum, Enums: []string{"pending", "completed", "failed"}},
{Name: "card_id", Type: field.TypeInt},
}
// PaymentsTable holds the schema information for the "payments" table.
PaymentsTable = &schema.Table{
Name: "payments",
Columns: PaymentsColumns,
PrimaryKey: []*schema.Column{PaymentsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "payments_cards_payments",
Columns: []*schema.Column{PaymentsColumns[6]},
RefColumns: []*schema.Column{CardsColumns[0]},
OnDelete: schema.NoAction,
},
},
Indexes: []*schema.Index{
{
Name: "payment_status_time",
Unique: false,
Columns: []*schema.Column{PaymentsColumns[5], PaymentsColumns[3]},
},
},
}
// PetsColumns holds the columns for the "pets" table.
PetsColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID},
{Name: "name", Type: field.TypeString},
{Name: "age", Type: field.TypeFloat64},
{Name: "weight", Type: field.TypeFloat64},
{Name: "best_friend_id", Type: field.TypeUUID, Unique: true, Nullable: true, Default: "00000000-0000-0000-0000-000000000000"},
{Name: "owner_id", Type: field.TypeInt, Default: 0},
}
// PetsTable holds the schema information for the "pets" table.
PetsTable = &schema.Table{
Name: "pets",
Columns: PetsColumns,
PrimaryKey: []*schema.Column{PetsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "pets_pets_best_friend",
Columns: []*schema.Column{PetsColumns[4]},
RefColumns: []*schema.Column{PetsColumns[0]},
OnDelete: schema.SetNull,
},
{
Symbol: "pets_users_owner",
Columns: []*schema.Column{PetsColumns[5]},
RefColumns: []*schema.Column{UsersColumns[0]},
OnDelete: schema.NoAction,
},
},
Indexes: []*schema.Index{
{
Name: "pet_name_owner_id",
Unique: true,
Columns: []*schema.Column{PetsColumns[1], PetsColumns[5]},
},
},
}
// SessionsColumns holds the columns for the "sessions" table.
SessionsColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID},
{Name: "active", Type: field.TypeBool, Default: false},
{Name: "issued_at", Type: field.TypeTime},
{Name: "expires_at", Type: field.TypeTime, Nullable: true},
{Name: "token", Type: field.TypeString, Nullable: true},
{Name: "method", Type: field.TypeJSON, Nullable: true},
{Name: "device_id", Type: field.TypeUUID, Nullable: true},
}
// SessionsTable holds the schema information for the "sessions" table.
SessionsTable = &schema.Table{
Name: "sessions",
Columns: SessionsColumns,
PrimaryKey: []*schema.Column{SessionsColumns[0]},
ForeignKeys: []*schema.ForeignKey{
{
Symbol: "sessions_session_devices_sessions",
Columns: []*schema.Column{SessionsColumns[6]},
RefColumns: []*schema.Column{SessionDevicesColumns[0]},
OnDelete: schema.SetNull,
},
},
Indexes: []*schema.Index{
{
Name: "session_active_expires_at",
Unique: false,
Columns: []*schema.Column{SessionsColumns[1], SessionsColumns[3]},
},
},
}
// SessionDevicesColumns holds the columns for the "session_devices" table.
SessionDevicesColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID},
{Name: "ip_address", Type: field.TypeString, Size: 50},
{Name: "user_agent", Type: field.TypeString, Size: 512},
{Name: "location", Type: field.TypeString, Size: 512},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime, Nullable: true},
}
// SessionDevicesTable holds the schema information for the "session_devices" table.
SessionDevicesTable = &schema.Table{
Name: "session_devices",
Columns: SessionDevicesColumns,
PrimaryKey: []*schema.Column{SessionDevicesColumns[0]},
Indexes: []*schema.Index{
{
Name: "sessiondevice_ip_address_user_agent",
Unique: false,
Columns: []*schema.Column{SessionDevicesColumns[1], SessionDevicesColumns[2]},
},
{
Name: "sessiondevice_location_updated_at",
Unique: false,
Columns: []*schema.Column{SessionDevicesColumns[3], SessionDevicesColumns[5]},
},
},
}
// UsersColumns holds the columns for the "users" table.
UsersColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt, Increment: true},
{Name: "age", Type: field.TypeFloat64},
{Name: "first_name", Type: field.TypeString},
{Name: "last_name", Type: field.TypeString},
{Name: "tags", Type: field.TypeJSON, Nullable: true},
}
// UsersTable holds the schema information for the "users" table.
UsersTable = &schema.Table{
Name: "users",
Columns: UsersColumns,
PrimaryKey: []*schema.Column{UsersColumns[0]},
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
CardsTable,
PaymentsTable,
PetsTable,
SessionsTable,
SessionDevicesTable,
UsersTable,
}
)
func init() {
CardsTable.ForeignKeys[0].RefTable = UsersTable
CardsTable.Annotation = &entsql.Annotation{}
CardsTable.Annotation.Checks = map[string]string{
"number_hash_length": "(LENGTH(`number_hash`) = 16)",
}
PaymentsTable.ForeignKeys[0].RefTable = CardsTable
PaymentsTable.Annotation = &entsql.Annotation{}
PaymentsTable.Annotation.Checks = map[string]string{
"amount_positive": "(`amount` > 0)",
}
PetsTable.ForeignKeys[0].RefTable = PetsTable
PetsTable.ForeignKeys[1].RefTable = UsersTable
SessionsTable.ForeignKeys[0].RefTable = SessionDevicesTable
SessionsTable.Annotation = &entsql.Annotation{}
SessionsTable.Annotation.Checks = map[string]string{
"token_length": "(LENGTH(`token`) = 64)",
}
UsersTable.Annotation = &entsql.Annotation{
Check: "age > 0",
}
UsersTable.Annotation.Checks = map[string]string{
"first_last_not_empty": "(`first_name` <> '' AND `last_name` <> '')",
}
}