-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [#280] Refactor Migration feature
- Loading branch information
Showing
127 changed files
with
9,068 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
with-expecter: True | ||
dir: "contracts" | ||
keeptree: True | ||
all: True | ||
all: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package schema | ||
|
||
import ( | ||
ormcontract "github.com/goravel/framework/contracts/database/orm" | ||
) | ||
|
||
type Blueprint interface { | ||
// Boolean Create a new boolean column on the table. | ||
Boolean(column string) ColumnDefinition | ||
// BigInteger Create a new big integer (8-byte) column on the table. | ||
BigInteger(column string) ColumnDefinition | ||
// Binary Create a new binary column on the table. | ||
Binary(column string) ColumnDefinition | ||
// Build Execute the blueprint to build / modify the table. | ||
Build(query ormcontract.Query, grammar Grammar) error | ||
// Char Create a new char column on the table. | ||
Char(column string, length ...int) ColumnDefinition | ||
// Comment Add a comment to the table. | ||
Comment(comment string) error | ||
// Create Indicate that the table needs to be created. | ||
Create() | ||
// Date Create a new date column on the table. | ||
Date(column string) ColumnDefinition | ||
// DateTime Create a new date-time column on the table. | ||
DateTime(column string) ColumnDefinition | ||
// DateTimeTz Create a new date-time column (with time zone) on the table. | ||
DateTimeTz(column string) ColumnDefinition | ||
// Decimal Create a new decimal column on the table. | ||
Decimal(column string) ColumnDefinition | ||
// Double Create a new double column on the table. | ||
Double(column string) ColumnDefinition | ||
// DropColumn Indicate that the given columns should be dropped. | ||
DropColumn(column string) error | ||
// DropForeign Indicate that the given foreign key should be dropped. | ||
DropForeign(index string) error | ||
// DropIndex Indicate that the given index should be dropped. | ||
DropIndex(index string) error | ||
// DropSoftDeletes Indicate that the soft delete column should be dropped. | ||
DropSoftDeletes() error | ||
// DropTimestamps Indicate that the timestamp columns should be dropped. | ||
DropTimestamps() error | ||
// Enum Create a new enum column on the table. | ||
Enum(column string, array []any) ColumnDefinition | ||
// Float Create a new float column on the table. | ||
Float(column string) ColumnDefinition | ||
// Foreign Specify a foreign key for the table. | ||
Foreign(columns []string, name ...string) error | ||
// GetAddedColumns Get the added columns. | ||
GetAddedColumns() []ColumnDefinition | ||
// GetChangedColumns Get the changed columns. | ||
GetChangedColumns() []ColumnDefinition | ||
// GetTableName Get the table name with prefix. | ||
GetTableName() string | ||
// ID Create a new auto-incrementing big integer (8-byte) column on the table. | ||
ID() ColumnDefinition | ||
// Index Specify an index for the table. | ||
Index(columns []string, name string) error | ||
// Integer Create a new integer (4-byte) column on the table. | ||
Integer(column string) ColumnDefinition | ||
// Json Create a new json column on the table. | ||
Json(column string) ColumnDefinition | ||
// Jsonb Create a new jsonb column on the table. | ||
Jsonb(column string) ColumnDefinition | ||
// Primary Specify the primary key(s) for the table. | ||
Primary(columns []string, name string) error | ||
// RenameColumn Indicate that the given columns should be renamed. | ||
RenameColumn(from, to string) error | ||
// RenameIndex Indicate that the given indexes should be renamed. | ||
RenameIndex(from, to string) error | ||
// SoftDeletes Add a "deleted at" timestamp for the table. | ||
SoftDeletes(column ...string) ColumnDefinition | ||
// SoftDeletesTz Add a "deleted at" timestampTz for the table. | ||
SoftDeletesTz(column ...string) ColumnDefinition | ||
// String Create a new string column on the table. | ||
String(column string, length ...int) ColumnDefinition | ||
// Text Create a new text column on the table. | ||
Text(column string) ColumnDefinition | ||
// Time Create a new time column on the table. | ||
Time(column string) ColumnDefinition | ||
// TimeTz Create a new time column (with time zone) on the table. | ||
TimeTz(column string) ColumnDefinition | ||
// Timestamp Create a new time column on the table. | ||
Timestamp(column string) ColumnDefinition | ||
// Timestamps Add nullable creation and update timestamps to the table. | ||
Timestamps() ColumnDefinition | ||
// TimestampsTz Add creation and update timestampTz columns to the table. | ||
TimestampsTz() ColumnDefinition | ||
// TimestampTz Create a new time column (with time zone) on the table. | ||
TimestampTz(column string) ColumnDefinition | ||
// ToSql Get the raw SQL statements for the blueprint. | ||
ToSql(query ormcontract.Query, grammar Grammar) []string | ||
// Unique Specify a unique index for the table. | ||
Unique(columns []string, name string) error | ||
// UnsignedInteger Create a new unsigned integer (4-byte) column on the table. | ||
UnsignedInteger(column string) ColumnDefinition | ||
// UnsignedBigInteger Create a new unsigned big integer (8-byte) column on the table. | ||
UnsignedBigInteger(column string) ColumnDefinition | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package schema | ||
|
||
type Column struct { | ||
AutoIncrement bool | ||
Collation string | ||
Comment string | ||
Default any | ||
Name string | ||
Nullable bool | ||
TypeName string | ||
Type string | ||
} | ||
|
||
type ColumnDefinition interface { | ||
// Change the column | ||
Change() | ||
// GetAllowed returns the allowed value | ||
GetAllowed() []string | ||
// GetAutoIncrement returns the autoIncrement value | ||
GetAutoIncrement() bool | ||
// GetLength returns the length value | ||
GetLength() int | ||
// GetName returns the name value | ||
GetName() string | ||
// GetPlaces returns the places value | ||
GetPlaces() int | ||
// GetPrecision returns the precision value | ||
GetPrecision() int | ||
// GetTotal returns the total value | ||
GetTotal() int | ||
// GetType returns the type value | ||
GetType() string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package schema | ||
|
||
import ( | ||
ormcontract "github.com/goravel/framework/contracts/database/orm" | ||
) | ||
|
||
type Grammar interface { | ||
// CompileAdd Compile an add column command. | ||
CompileAdd(blueprint Blueprint, command string) string | ||
// CompileAutoIncrementStartingValues Compile the auto-incrementing column starting values. | ||
CompileAutoIncrementStartingValues(blueprint Blueprint, command string) string | ||
// CompileChange Compile a change column command into a series of SQL statements. | ||
CompileChange(blueprint Blueprint, command, connection string) string | ||
// CompileColumns Compile the query to determine the columns. | ||
// TODO check if the database is required | ||
CompileColumns(database, table, schema string) string | ||
// CompileCreate Compile a create table command. | ||
CompileCreate(blueprint Blueprint, query ormcontract.Query) string | ||
// CompileCreateEncoding Append the character set specifications to a command. | ||
CompileCreateEncoding(sql, connection string, blueprint Blueprint) string | ||
// CompileCreateEngine Append the engine specifications to a command. | ||
CompileCreateEngine(sql, connection string, blueprint Blueprint) string | ||
// CompileCreateTable Create the main create table clause. | ||
CompileCreateTable(blueprint Blueprint, command, connection string) string | ||
// CompileDrop Compile a drop table command. | ||
CompileDrop(blueprint Blueprint, command string) string | ||
// CompileDropAllTables Compile the SQL needed to drop all tables. | ||
CompileDropAllTables(tables []string) string | ||
// CompileDropAllViews Compile the SQL needed to drop all views. | ||
CompileDropAllViews(views []string) string | ||
// CompileDropColumn Compile a drop column command. | ||
CompileDropColumn(blueprint Blueprint, command string) string | ||
// CompileDropIfExists Compile a drop table (if exists) command. | ||
CompileDropIfExists(blueprint Blueprint, command string) string | ||
// CompileDropIndex Compile a drop index command. | ||
CompileDropIndex(blueprint Blueprint, command string) string | ||
// CompileDropPrimary Compile a drop primary key command. | ||
CompileDropPrimary(blueprint Blueprint, command string) string | ||
// CompileDropUnique Compile a drop unique key command. | ||
CompileDropUnique(blueprint Blueprint, command string) string | ||
// CompilePrimary Compile a primary key command. | ||
CompilePrimary(blueprint Blueprint, command string) string | ||
// CompileIndex Compile a plain index key command. | ||
CompileIndex(blueprint Blueprint, command string) string | ||
// CompileIndexes Compile the query to determine the indexes. | ||
CompileIndexes(database, table string) string | ||
// CompileRename Compile a rename table command. | ||
CompileRename(blueprint Blueprint, command string) string | ||
// CompileRenameColumn Compile a rename column command. | ||
CompileRenameColumn(blueprint Blueprint, command, connection string) string | ||
// CompileRenameIndex Compile a rename index command. | ||
CompileRenameIndex(blueprint Blueprint, command string) string | ||
// CompileTableComment Compile a table comment command. | ||
CompileTableComment(blueprint Blueprint, command string) string | ||
// CompileTables Compile the query to determine the tables. | ||
CompileTables(database string) string | ||
// CompileUnique Compile a unique key command. | ||
CompileUnique(blueprint Blueprint, command string) string | ||
// CompileViews Compile the query to determine the views. | ||
CompileViews(database string) string | ||
// ModifyNullable Get the SQL for a nullable column modifier. | ||
ModifyNullable(blueprint Blueprint, column string) string | ||
// ModifyDefault Get the SQL for a default column modifier. | ||
ModifyDefault(blueprint Blueprint, column string) string | ||
// TypeBigInteger Create the column definition for a big integer type. | ||
TypeBigInteger(column ColumnDefinition) string | ||
// TypeBinary Create the column definition for a binary type. | ||
TypeBinary(column ColumnDefinition) string | ||
// TypeBoolean Create the column definition for a boolean type. | ||
TypeBoolean(column ColumnDefinition) string | ||
// TypeChar Create the column definition for a char type. | ||
TypeChar(column ColumnDefinition) string | ||
// TypeDate Create the column definition for a date type. | ||
TypeDate(column ColumnDefinition) string | ||
// TypeDateTime Create the column definition for a date-time type. | ||
TypeDateTime(column ColumnDefinition) string | ||
// TypeDateTimeTz Create the column definition for a date-time (with time zone) type. | ||
TypeDateTimeTz(column ColumnDefinition) string | ||
// TypeDecimal Create the column definition for a decimal type. | ||
TypeDecimal(column ColumnDefinition) string | ||
// TypeDouble Create the column definition for a double type. | ||
TypeDouble(column ColumnDefinition) string | ||
// TypeEnum Create the column definition for an enumeration type. | ||
TypeEnum(column ColumnDefinition) string | ||
// TypeFloat Create the column definition for a float type. | ||
TypeFloat(column ColumnDefinition) string | ||
// TypeInteger Create the column definition for an integer type. | ||
TypeInteger(column ColumnDefinition) string | ||
// TypeJson Create the column definition for a json type. | ||
TypeJson(column ColumnDefinition) string | ||
// TypeJsonb Create the column definition for a jsonb type. | ||
TypeJsonb(column ColumnDefinition) string | ||
// TypeString Create the column definition for a string type. | ||
TypeString(column ColumnDefinition) string | ||
// TypeText Create the column definition for a text type. | ||
TypeText(column ColumnDefinition) string | ||
// TypeTime Create the column definition for a time type. | ||
TypeTime(column ColumnDefinition) string | ||
// TypeTimeTz Create the column definition for a time (with time zone) type. | ||
TypeTimeTz(column ColumnDefinition) string | ||
// TypeTimestamp Create the column definition for a timestamp type. | ||
TypeTimestamp(column ColumnDefinition) string | ||
// TypeTimestampTz Create the column definition for a timestamp (with time zone) type. | ||
TypeTimestampTz(column ColumnDefinition) string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package schema | ||
|
||
type Processor interface { | ||
// ProcessColumns Process the results of a columns query. | ||
ProcessColumns(columns []Column) []Column | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package schema | ||
|
||
type Schema interface { | ||
Connection(name string) Schema | ||
// Create a new table on the schema. | ||
Create(table string, callback func(table Blueprint)) error | ||
// Drop a table from the schema. | ||
Drop(table string) error | ||
// DropAllTables Drop all tables from the database. | ||
DropAllTables() error | ||
// DropAllViews Drop all views from the database. | ||
DropAllViews() error | ||
// DropColumns Drop columns from a table schema. | ||
DropColumns(table string, columns []string) error | ||
// DropIfExists Drop a table from the schema if it exists. | ||
DropIfExists(table string) error | ||
// GetColumns Get the columns for a given table. | ||
GetColumns(table string) ([]Column, error) | ||
// GetColumnListing Get the column listing for a given table. | ||
GetColumnListing(table string) []string | ||
// GetIndexes Get the indexes for a given table. | ||
GetIndexes(table string) []Index | ||
// GetIndexListing Get the names of the indexes for a given table. | ||
GetIndexListing(table string) []string | ||
// GetTableListing Get the names of the tables that belong to the database. | ||
GetTableListing() []string | ||
// GetTables Get the tables that belong to the database. | ||
GetTables() ([]Table, error) | ||
// GetViews Get the views that belong to the database. | ||
GetViews() []View | ||
// HasColumn Determine if the given table has a given column. | ||
HasColumn(table, column string) bool | ||
// HasColumns Determine if the given table has given columns. | ||
HasColumns(table string, columns []string) bool | ||
// HasIndex Determine if the given table has a given index. | ||
HasIndex(table, index string) | ||
// HasTable Determine if the given table exists. | ||
HasTable(table string) bool | ||
// HasView Determine if the given view exists. | ||
HasView(view string) bool | ||
// Register migrations. | ||
Register([]Migration) | ||
// Rename a table on the schema. | ||
Rename(from, to string) | ||
// Table Modify a table on the schema. | ||
Table(table string, callback func(table Blueprint)) error | ||
} | ||
|
||
type Migration interface { | ||
Signature() string | ||
Up() error | ||
Down() error | ||
} | ||
|
||
type Index struct { | ||
Columns []string | ||
Name string | ||
Primary bool | ||
Type string | ||
Unique bool | ||
} | ||
|
||
type Table struct { | ||
Name string | ||
Size int | ||
} | ||
|
||
type View struct { | ||
Definition string | ||
Name string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.