Compare commits
2 commits
bf5180559f
...
8ffd6d0050
Author | SHA1 | Date | |
---|---|---|---|
8ffd6d0050 | |||
484bb95820 |
5 changed files with 57 additions and 15 deletions
37
cmd/migrate-new/main.go
Normal file
37
cmd/migrate-new/main.go
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
|
||||||
|
"git.mstar.dev/mstar/goutils/other"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
"gorm.io/driver/postgres"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"git.mstar.dev/mstar/linstrom/config"
|
||||||
|
"git.mstar.dev/mstar/linstrom/shared"
|
||||||
|
"git.mstar.dev/mstar/linstrom/storage-new"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
other.SetupFlags()
|
||||||
|
flag.Parse()
|
||||||
|
other.ConfigureLogging(nil)
|
||||||
|
if err := config.ReadAndWriteToGlobal(*shared.FlagConfigFile); err != nil {
|
||||||
|
log.Fatal().Err(err).Send()
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := gorm.Open(
|
||||||
|
postgres.Open(config.GlobalConfig.Storage.BuildPostgresDSN()),
|
||||||
|
&gorm.Config{
|
||||||
|
PrepareStmt: false,
|
||||||
|
Logger: shared.NewGormLogger(log.Logger),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("Failed to open connection to temporary container")
|
||||||
|
}
|
||||||
|
if err := storage.Migrate(db); err != nil {
|
||||||
|
log.Fatal().Err(err).Send()
|
||||||
|
}
|
||||||
|
}
|
|
@ -82,7 +82,7 @@ func createRemoteServerSoftwareType(db *gorm.DB) error {
|
||||||
|
|
||||||
// Helper function for ensuring the existence of an enum with the given values
|
// Helper function for ensuring the existence of an enum with the given values
|
||||||
func migrateEnum(db *gorm.DB, name string, values []string) error {
|
func migrateEnum(db *gorm.DB, name string, values []string) error {
|
||||||
if err := db.Exec("DROP TYPE IF EXISTS " + name).Error; err != nil {
|
if err := db.Exec("DROP TYPE IF EXISTS " + name + " CASCADE;").Error; err != nil {
|
||||||
return other.Error(
|
return other.Error(
|
||||||
"storage",
|
"storage",
|
||||||
fmt.Sprintf("Failed to remove old type %s (if it exists)", name),
|
fmt.Sprintf("Failed to remove old type %s (if it exists)", name),
|
||||||
|
@ -90,9 +90,9 @@ func migrateEnum(db *gorm.DB, name string, values []string) error {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
queryBuilder := strings.Builder{}
|
queryBuilder := strings.Builder{}
|
||||||
queryBuilder.WriteString("CREATE TYPE")
|
queryBuilder.WriteString("CREATE TYPE ")
|
||||||
queryBuilder.WriteString(name)
|
queryBuilder.WriteString(name)
|
||||||
queryBuilder.WriteString("AS ENUM (")
|
queryBuilder.WriteString(" AS ENUM (")
|
||||||
blen := len(values)
|
blen := len(values)
|
||||||
for i, btype := range values {
|
for i, btype := range values {
|
||||||
queryBuilder.WriteString("'" + string(btype) + "'")
|
queryBuilder.WriteString("'" + string(btype) + "'")
|
||||||
|
@ -101,6 +101,7 @@ func migrateEnum(db *gorm.DB, name string, values []string) error {
|
||||||
queryBuilder.WriteString(",")
|
queryBuilder.WriteString(",")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
queryBuilder.WriteString(");")
|
||||||
if err := db.Exec(queryBuilder.String()).Error; err != nil {
|
if err := db.Exec(queryBuilder.String()).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ type Note struct {
|
||||||
// Soft delete means that this entry still exists in the db, but gorm won't include it anymore unless specifically told to
|
// Soft delete means that this entry still exists in the db, but gorm won't include it anymore unless specifically told to
|
||||||
// If not null, this entry is marked as deleted
|
// If not null, this entry is marked as deleted
|
||||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||||
// Creator Account // `gorm:"foreignKey:CreatorId;references:ID"` // Account that created the post
|
Creator User
|
||||||
CreatorId string
|
CreatorId string
|
||||||
Remote bool // Whether the note is originally a remote one and just "cached"
|
Remote bool // Whether the note is originally a remote one and just "cached"
|
||||||
// Raw content of the note. So without additional formatting applied
|
// Raw content of the note. So without additional formatting applied
|
||||||
|
|
|
@ -9,6 +9,7 @@ type RemoteServer struct {
|
||||||
ServerType ServerSoftwareType // What software the server is running. Useful for formatting
|
ServerType ServerSoftwareType // What software the server is running. Useful for formatting
|
||||||
Domain string // `gorm:"primaryKey"` // Domain the server exists under. Additional primary key
|
Domain string // `gorm:"primaryKey"` // Domain the server exists under. Additional primary key
|
||||||
Name string // What the server wants to be known as (usually same as url)
|
Name string // What the server wants to be known as (usually same as url)
|
||||||
Icon string // ID of a media file
|
Icon MediaMetadata
|
||||||
|
IconId string // ID of a media file
|
||||||
IsSelf bool // Whether this server is yours truly
|
IsSelf bool // Whether this server is yours truly
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,9 +36,12 @@ type User struct {
|
||||||
DisplayName string // The display name of the user. Can be different from the handle
|
DisplayName string // The display name of the user. Can be different from the handle
|
||||||
Description string // The description of a user account
|
Description string // The description of a user account
|
||||||
IsBot bool // Whether to mark this account as a script controlled one
|
IsBot bool // Whether to mark this account as a script controlled one
|
||||||
Icon string // ID of a media file used as icon
|
Icon MediaMetadata
|
||||||
Background *string // ID of a media file used as background image
|
IconId string // ID of a media file used as icon
|
||||||
Banner *string // ID of a media file used as banner
|
Background *MediaMetadata
|
||||||
|
BackgroundId *string // ID of a media file used as background image
|
||||||
|
Banner *MediaMetadata
|
||||||
|
BannerId *string // ID of a media file used as banner
|
||||||
Indexable bool // Whether this account can be found by crawlers
|
Indexable bool // Whether this account can be found by crawlers
|
||||||
PublicKey []byte // The public key of the account
|
PublicKey []byte // The public key of the account
|
||||||
// Whether this account restricts following
|
// Whether this account restricts following
|
||||||
|
|
Loading…
Reference in a new issue