-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ShkrutDenis/develop
Develop
- Loading branch information
Showing
22 changed files
with
1,174 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
.idea | ||
.env | ||
.docker-compose | ||
docker-compose.yml |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package builder | ||
|
||
import ( | ||
"github.com/ShkrutDenis/go-migrations/builder/contract" | ||
mysql "github.com/ShkrutDenis/go-migrations/builder/mysql/table" | ||
postgres "github.com/ShkrutDenis/go-migrations/builder/postgress/table" | ||
"github.com/jmoiron/sqlx" | ||
"os" | ||
) | ||
|
||
func NewTable(name string, con *sqlx.DB) contract.Table { | ||
switch os.Getenv("DB_DRIVER") { | ||
case "mysql": | ||
return mysql.NewTable(name, con) | ||
case "postgres": | ||
return postgres.NewTable(name, con) | ||
default: | ||
panic("Not supported DB driver: " + os.Getenv("DB_DRIVER")) | ||
} | ||
} | ||
|
||
func DropTable(name string, con *sqlx.DB) contract.Table { | ||
switch os.Getenv("DB_DRIVER") { | ||
case "mysql": | ||
return mysql.DropTable(name, con) | ||
case "postgres": | ||
return postgres.DropTable(name, con) | ||
default: | ||
panic("Not supported DB driver: " + os.Getenv("DB_DRIVER")) | ||
} | ||
} | ||
|
||
func ChangeTable(name string, con *sqlx.DB) contract.Table { | ||
switch os.Getenv("DB_DRIVER") { | ||
case "mysql": | ||
return mysql.ChangeTable(name, con) | ||
case "postgres": | ||
return postgres.ChangeTable(name, con) | ||
default: | ||
panic("Not supported DB driver: " + os.Getenv("DB_DRIVER")) | ||
} | ||
} | ||
|
||
func RenameTable(oldName, newName string, con *sqlx.DB) contract.Table { | ||
switch os.Getenv("DB_DRIVER") { | ||
case "mysql": | ||
return mysql.RenameTable(oldName, newName, con) | ||
case "postgres": | ||
return postgres.RenameTable(oldName, newName, con) | ||
default: | ||
panic("Not supported DB driver: " + os.Getenv("DB_DRIVER")) | ||
} | ||
} |
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,29 @@ | ||
package contract | ||
|
||
type Column interface { | ||
Type(string) Column | ||
Nullable() Column | ||
NotNull() Column | ||
Autoincrement() Column | ||
NotAutoincrement() Column | ||
Default(string) Column | ||
Primary() Column | ||
Unique() Column | ||
NotUnique() Column | ||
Drop() Column | ||
Change() Column | ||
First() Column | ||
After(string) Column | ||
Rename(string) Column | ||
GetSQL() string | ||
GetName() string | ||
GetUniqueKeyName() string | ||
IsPrimary() bool | ||
IsUnique() bool | ||
HasUniqueKey() bool | ||
NeedUniqueKey() bool | ||
NeedDropUniqueKey() bool | ||
IsWaitingDrop() bool | ||
IsWaitingRename() bool | ||
IsWaitingChange() bool | ||
} |
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,14 @@ | ||
package contract | ||
|
||
type ForeignKey interface { | ||
Reference(string) ForeignKey | ||
On(string) ForeignKey | ||
OnUpdate(string) ForeignKey | ||
OnDelete(string) ForeignKey | ||
Drop() ForeignKey | ||
SetKeyName(string) ForeignKey | ||
GenerateKeyName() ForeignKey | ||
GetSQL() string | ||
GetName() string | ||
ForDrop() bool | ||
} |
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,16 @@ | ||
package contract | ||
|
||
type Table interface { | ||
Column(string) Column | ||
String(string, int) Column | ||
Integer(string) Column | ||
WithTimestamps() Table | ||
RenameColumn(string, string) Column | ||
DropColumn(string) Column | ||
PrimaryKey(string) Column | ||
ForeignKey(string) ForeignKey | ||
DropForeignKey(string) Table | ||
GetSQL() string | ||
Exec() error | ||
MustExec() | ||
} |
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,13 @@ | ||
package contract | ||
|
||
import "github.com/jmoiron/sqlx" | ||
|
||
type UniqueKey interface { | ||
SetKeyName(string) UniqueKey | ||
GenerateKeyName() UniqueKey | ||
Drop() UniqueKey | ||
GetSQL() string | ||
Exec(*sqlx.DB) error | ||
MustExec(*sqlx.DB) | ||
GetName() 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
File renamed without changes.
Oops, something went wrong.