-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1480ce
commit 98c1b0d
Showing
9 changed files
with
81 additions
and
7 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
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,12 +1,12 @@ | ||
CREATE TABLE IF NOT EXISTS `item` ( | ||
`id` INT NOT NULL AUTO_INCREMENT, | ||
`name` VARCHAR(100) NOT NULL, | ||
`overview` TEXT NOT NULL DEFAULT '', | ||
`overview` TEXT NOT NULL, | ||
`icon` BLOB NOT NULL, | ||
`type` INT NOT NULL, | ||
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`created_by` INT NOT NULL, | ||
`updated_at` DATETIME NOT NULL DEFAULT DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
`updated_by` INT NOT NULL, | ||
PRIMARY KEY (`id`)) | ||
ENGINE = InnoDB; |
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
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,40 @@ | ||
package main | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
|
||
"github.com/golang-migrate/migrate/v4" | ||
"github.com/golang-migrate/migrate/v4/database/mysql" | ||
_ "github.com/golang-migrate/migrate/v4/source/file" | ||
) | ||
|
||
func main() { | ||
db, err := sql.Open("mysql", "kiritan:kiritan@tcp(localhost:3306)/kiritan") | ||
|
||
if err != nil { | ||
fmt.Println("DBの接続に失敗しました") | ||
fmt.Printf("%s\n", err) | ||
return | ||
} | ||
|
||
driver, err := mysql.WithInstance(db, &mysql.Config{}) | ||
|
||
if err != nil { | ||
fmt.Println("Hoge") | ||
fmt.Printf("%s\n", err) | ||
return | ||
} | ||
|
||
m, err := migrate.NewWithDatabaseInstance("file://db/migration", "mysql", driver) | ||
if err != nil { | ||
fmt.Printf("%s\n", err) | ||
return | ||
} | ||
|
||
err = m.Up() | ||
if err != nil && err != migrate.ErrNoChange { | ||
fmt.Printf("%s\n", err) | ||
return | ||
} | ||
} |