mirror of https://github.com/docker/docs.git
Attempt to match the model exactly up with the initial sql + the
migrate sql. Signed-off-by: Ying Li <ying.li@docker.com>
This commit is contained in:
parent
1bb1f1acd2
commit
e8528ec391
|
@ -0,0 +1,18 @@
|
||||||
|
-- This migrates initial.sql to tables that are needed for GORM
|
||||||
|
|
||||||
|
ALTER TABLE `tuf_files`
|
||||||
|
ADD COLUMN `created_at` timestamp NULL AFTER `id`,
|
||||||
|
ADD COLUMN `updated_at` timestamp NULL AFTER `created_at`,
|
||||||
|
ADD COLUMN `deleted_at` timestamp NULL AFTER `updated_at`,
|
||||||
|
MODIFY `id` int(10) unsigned AUTO_INCREMENT;
|
||||||
|
|
||||||
|
ALTER TABLE `timestamp_keys`
|
||||||
|
ADD COLUMN `id` int(10) unsigned AUTO_INCREMENT FIRST,
|
||||||
|
ADD COLUMN `created_at` timestamp NULL AFTER `id`,
|
||||||
|
ADD COLUMN `updated_at` timestamp NULL AFTER `created_at`,
|
||||||
|
ADD COLUMN `deleted_at` timestamp NULL AFTER `updated_at`,
|
||||||
|
DROP PRIMARY KEY,
|
||||||
|
ADD PRIMARY KEY (`id`),
|
||||||
|
ADD UNIQUE (`gun`);
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ type TUFFile struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Gun string `sql:"type:varchar(255);not null"`
|
Gun string `sql:"type:varchar(255);not null"`
|
||||||
Role string `sql:"type:varchar(255);not null"`
|
Role string `sql:"type:varchar(255);not null"`
|
||||||
Version int
|
Version int `sql:"not null"`
|
||||||
Data []byte `sql:"type:longblob"`
|
Data []byte `sql:"type:longblob;not null"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName sets a specific table name for TUFFile
|
// TableName sets a specific table name for TUFFile
|
||||||
|
@ -19,8 +19,8 @@ func (g TUFFile) TableName() string {
|
||||||
// TimestampKey represents a single timestamp key in the database
|
// TimestampKey represents a single timestamp key in the database
|
||||||
type TimestampKey struct {
|
type TimestampKey struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Gun string `sql:"type:varchar(255);unique"`
|
Gun string `sql:"type:varchar(255);unique;not null"`
|
||||||
Cipher string `sql:"type:varchar(30)"`
|
Cipher string `sql:"type:varchar(30);not null"`
|
||||||
Public []byte `sql:"type:blob;not null"`
|
Public []byte `sql:"type:blob;not null"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,8 @@ func (g TimestampKey) TableName() string {
|
||||||
|
|
||||||
// CreateTUFTable creates the DB table for TUFFile
|
// CreateTUFTable creates the DB table for TUFFile
|
||||||
func CreateTUFTable(db gorm.DB) error {
|
func CreateTUFTable(db gorm.DB) error {
|
||||||
query := db.CreateTable(&TUFFile{})
|
// TODO: gorm
|
||||||
|
query := db.Set("gorm:table_options", "ENGINE=InnoDB DEFAULT CHARSET=utf8").CreateTable(&TUFFile{})
|
||||||
if query.Error != nil {
|
if query.Error != nil {
|
||||||
return query.Error
|
return query.Error
|
||||||
}
|
}
|
||||||
|
@ -45,7 +46,7 @@ func CreateTUFTable(db gorm.DB) error {
|
||||||
|
|
||||||
// CreateTimestampTable creates the DB table for TUFFile
|
// CreateTimestampTable creates the DB table for TUFFile
|
||||||
func CreateTimestampTable(db gorm.DB) error {
|
func CreateTimestampTable(db gorm.DB) error {
|
||||||
query := db.CreateTable(&TimestampKey{})
|
query := db.Set("gorm:table_options", "ENGINE=InnoDB DEFAULT CHARSET=utf8").CreateTable(&TimestampKey{})
|
||||||
if query.Error != nil {
|
if query.Error != nil {
|
||||||
return query.Error
|
return query.Error
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue