Skip to content

Commit d223e0d

Browse files
committed
Fix bug with NOT null constraint
1 parent cc74ff5 commit d223e0d

File tree

5 files changed

+5
-10
lines changed

5 files changed

+5
-10
lines changed

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ buildscript {
1717
}
1818

1919
plugins {
20-
id 'com.android.application' version '8.8.0' apply false
21-
id 'com.android.library' version '8.8.0' apply false
20+
id 'com.android.application' version '8.8.2' apply false
21+
id 'com.android.library' version '8.8.2' apply false
2222
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
2323
}
2424

api/pkg/di/container.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,6 @@ func (container *Container) DB() (db *gorm.DB) {
321321

322322
container.logger.Debug(fmt.Sprintf("Running migrations for %T", db))
323323

324-
// This prevents a bug in the Gorm AutoMigrate where it tries to delete this no existent constraints
325-
db.Exec(`
326-
ALTER TABLE users ADD CONSTRAINT IF NOT EXISTS uni_users_api_key CHECK (api_key IS NOT NULL);
327-
ALTER TABLE discords ADD CONSTRAINT IF NOT EXISTS uni_discords_server_id CHECK (server_id IS NOT NULL);`)
328-
329324
if err = db.AutoMigrate(&entities.Message{}); err != nil {
330325
container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Message{})))
331326
}

api/pkg/entities/discord.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Discord struct {
1111
ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"`
1212
UserID UserID `json:"user_id" gorm:"index" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"`
1313
Name string `json:"name" example:"Game Server"`
14-
ServerID string `json:"server_id" gorm:"uniqueIndex:idx_discords_server_id" example:"1095778291488653372"`
14+
ServerID string `json:"server_id" gorm:"uniqueIndex:idx_discords_server_id;NOT NULL" example:"1095778291488653372"`
1515
IncomingChannelID string `json:"incoming_channel_id" example:"1095780203256627291"`
1616
CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"`
1717
UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"`

api/pkg/entities/phone_api_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type PhoneAPIKey struct {
1515
UserEmail string `json:"user_email" example:"[email protected]"`
1616
PhoneNumbers pq.StringArray `json:"phone_numbers" example:"[+18005550199,+18005550100]" gorm:"type:text[]" swaggertype:"array,string"`
1717
PhoneIDs pq.StringArray `json:"phone_ids" example:"[32343a19-da5e-4b1b-a767-3298a73703cb,32343a19-da5e-4b1b-a767-3298a73703cc]" gorm:"type:text[]" swaggertype:"array,string"`
18-
APIKey string `json:"api_key" gorm:"uniqueIndex:idx_phone_api_key__api_key" example:"pk_DGW8NwQp7mxKaSZ72Xq9v6xxxxx"`
18+
APIKey string `json:"api_key" gorm:"uniqueIndex:idx_phone_api_key__api_key;NOT NULL" example:"pk_DGW8NwQp7mxKaSZ72Xq9v6xxxxx"`
1919
CreatedAt time.Time `json:"created_at" example:"2022-06-05T14:26:02.302718+03:00"`
2020
UpdatedAt time.Time `json:"updated_at" example:"2022-06-05T14:26:02.302718+03:00"`
2121
}

api/pkg/entities/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const SubscriptionName20KYearly = SubscriptionName("20k-yearly")
7474
type User struct {
7575
ID UserID `json:"id" gorm:"primaryKey;type:string;" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"`
7676
Email string `json:"email" example:"[email protected]"`
77-
APIKey string `json:"api_key" gorm:"uniqueIndex:idx_users_api_key" example:"x-api-key"`
77+
APIKey string `json:"api_key" gorm:"uniqueIndex:idx_users_api_key;NOT NULL" example:"x-api-key"`
7878
Timezone string `json:"timezone" example:"Europe/Helsinki" gorm:"default:Africa/Accra"`
7979
ActivePhoneID *uuid.UUID `json:"active_phone_id" gorm:"type:uuid;" example:"32343a19-da5e-4b1b-a767-3298a73703cb"`
8080
SubscriptionName SubscriptionName `json:"subscription_name" example:"free"`

0 commit comments

Comments
 (0)