-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flag migrations as yaml
- Loading branch information
Drew Foehn
committed
Mar 30, 2024
1 parent
770461b
commit 08e5b71
Showing
14 changed files
with
517 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"contributes": { | ||
"jsonValidation": [ | ||
{ | ||
"fileMatch": "migrations/*.yaml", | ||
"url": "migrations/.schema.json" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Migrations | ||
|
||
Users can create flag collections as yaml files within a migration directory and run flagr to insert/modify flags. | ||
This allows for developers to create flags as deployment assets and allows for migrating flags through various environments whilst keeping keys stable. | ||
|
||
Each found flag is upserted into the database. Then the flag has all segments, variants and tags removed then replaced with the new flag properties. | ||
|
||
As an example, create a file named `migrations/202403030000.yaml` with the following content: | ||
```yaml | ||
--- | ||
# this is a basic flag | ||
- key: SIMPLE-FLAG-1 | ||
description: a toggle for just one user | ||
enabled: true | ||
segments: | ||
- description: flag for just for one email [email protected] | ||
rank: 0 | ||
rolloutPercent: 100 | ||
constraints: | ||
- property: email | ||
operator: EQ | ||
value: '"[email protected]"' | ||
distributions: | ||
- variantKey: "on" | ||
percent: 100 | ||
- rank: 1 | ||
rolloutPercent: 100 | ||
constraints: [] | ||
distributions: | ||
- variantKey: "off" | ||
percent: 100 | ||
variants: | ||
- key: "off" | ||
attachment: {} | ||
- key: "on" | ||
attachment: {} | ||
entityType: User | ||
dataRecordsEnabled: true | ||
|
||
``` | ||
|
||
```shell | ||
$ flagr -m | ||
INFO[0146] 1 new migrations completed (1 total) | ||
``` | ||
Once the application is ran, flagr will scan the migration files, insert them into the db and shut down. | ||
|
||
### Config | ||
Location of yaml configs can be set with either argument or env var. | ||
``` | ||
FLAGR_MIGRATION_PATH=./migrations/ ./flagr -m | ||
./flagr -m --migrationPath=`pwd`/migrations | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"key": { | ||
"type": "string" | ||
}, | ||
"description": { | ||
"type": "string" | ||
}, | ||
"enabled": { | ||
"type": "boolean" | ||
}, | ||
"segments": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"description": { | ||
"type": "string" | ||
}, | ||
"rank": { | ||
"type": "integer" | ||
}, | ||
"rolloutPercent": { | ||
"type": "integer" | ||
}, | ||
"constraints": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"property": { | ||
"type": "string" | ||
}, | ||
"operator": { | ||
"type": "string" | ||
}, | ||
"value": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"property", | ||
"operator", | ||
"value" | ||
] | ||
} | ||
}, | ||
"distributions": { | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"variantKey": { | ||
"type": "string" | ||
}, | ||
"percent": { | ||
"type": "integer" | ||
} | ||
}, | ||
"required": [ | ||
"variantKey", | ||
"percent" | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"rank", | ||
"rolloutPercent", | ||
"distributions" | ||
] | ||
} | ||
}, | ||
"variants": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"key": { | ||
"type": "string" | ||
}, | ||
"attachment": { | ||
"type": "object" | ||
} | ||
}, | ||
"required": [ | ||
"key" | ||
] | ||
} | ||
}, | ||
"entityType": { | ||
"type": "string" | ||
}, | ||
"dataRecordsEnabled": { | ||
"type": "boolean" | ||
}, | ||
"tags": { | ||
"type": "array", | ||
"items": | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"value": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"value" | ||
] | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"key", | ||
"description", | ||
"enabled" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package entity | ||
|
||
import "gorm.io/gorm" | ||
|
||
type FlagMigration struct { | ||
gorm.Model | ||
|
||
Name string `gorm:"type:varchar(64);uniqueIndex:idx_flag_migration_name"` | ||
} |
Oops, something went wrong.