Created
May 12, 2022 23:30
-
-
Save manakuro/6428a3ea5f0f699d4bbbd71f7758f3bd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package main | |
import ( | |
"context" | |
"log" | |
"planetscale-witn-ent/config" | |
"planetscale-witn-ent/datastore" | |
"planetscale-witn-ent/ent" | |
"planetscale-witn-ent/ent/migrate" | |
) | |
func main() { | |
config.ReadConfig(config.ReadConfigOption{}) | |
client, err := datastore.NewClient(datastore.NewClientOptions{}) | |
if err != nil { | |
log.Fatalf("failed opening mysql client: %v", err) | |
} | |
defer client.Close() | |
db := client.DB() | |
_, err = db.Exec("SET GLOBAL read_only = OFF;") | |
if err != nil { | |
log.Fatalf("failed changing mysql config: %v", err) | |
} | |
createDBSchema(client) | |
} | |
func createDBSchema(client *ent.Client) { | |
if err := client.Schema.Create( | |
context.Background(), | |
migrate.WithDropIndex(true), | |
migrate.WithDropColumn(true), | |
migrate.WithForeignKeys(false), | |
); err != nil { | |
log.Fatalf("failed creating schema resources: %v", err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment