MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/golang-samples / migrateDB

Function migrateDB

cloudsql/sqlserver/database-sql/cloudsql.go:50–63  ·  view source on GitHub ↗

migrateDB creates the votes table if it does not already exist.

(db *sql.DB)

Source from the content-addressed store, hash-verified

48
49// migrateDB creates the votes table if it does not already exist.
50func migrateDB(db *sql.DB) error {
51 // Drop the votes table if it already exists.
52 if _, err := db.Exec("DROP TABLE IF EXISTS votes;"); err != nil {
53 log.Fatalf("DB.Exec: unable to drop votes table: %v", err)
54 }
55 // Create the votes table.
56 createVotes := `CREATE TABLE votes (
57 id int IDENTITY(1,1) PRIMARY KEY,
58 created_at DATETIME NOT NULL,
59 candidate CHAR(6) NOT NULL
60 );`
61 _, err := db.Exec(createVotes)
62 return err
63}
64
65// recentVotes returns the last five votes cast.
66func recentVotes(db *sql.DB) ([]vote, error) {

Callers 1

mustConnectFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected