- Model golem15_user_oauth_identities with Encrypted tokens and empty Fillable
- gormigrate 202610050001 with both unique indexes, cascade FK, and jsonb profile_data
- OAuthIdentitiesIndex returns {"data":[]} for a signed-in caller with no rows
37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package updates
|
|
|
|
import (
|
|
"github.com/go-gormigrate/gormigrate/v2"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
var oauthIdentityMigrations = []*gormigrate.Migration{
|
|
{
|
|
ID: "202610050001_create_oauth_identities",
|
|
Migrate: func(tx *gorm.DB) error {
|
|
return execStmts(tx, []string{
|
|
`CREATE TABLE golem15_user_oauth_identities (
|
|
id SERIAL PRIMARY KEY,
|
|
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
provider VARCHAR(50) NOT NULL,
|
|
provider_id VARCHAR(255) NOT NULL,
|
|
access_token TEXT NULL,
|
|
refresh_token TEXT NULL,
|
|
token_expires_at TIMESTAMPTZ NULL,
|
|
profile_data jsonb NULL,
|
|
linked_at TIMESTAMPTZ NULL,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
)`,
|
|
`CREATE UNIQUE INDEX oauth_identities_user_provider_unique ON golem15_user_oauth_identities (user_id, provider)`,
|
|
`CREATE UNIQUE INDEX oauth_identities_provider_identity_unique ON golem15_user_oauth_identities (provider, provider_id)`,
|
|
})
|
|
},
|
|
Rollback: func(tx *gorm.DB) error {
|
|
return tx.Exec("DROP TABLE IF EXISTS golem15_user_oauth_identities").Error
|
|
},
|
|
},
|
|
}
|
|
|
|
func init() { Register(oauthIdentityMigrations...) }
|