-
Notifications
You must be signed in to change notification settings - Fork 186
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
Showing
24 changed files
with
1,086 additions
and
0 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
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 | ||
$ curl http://localhost:8000/api/v1/migrations | ||
{"code":200,"message":"1 new migrations completed","migrations":["202403030000.yaml"]} | ||
``` | ||
Once the endpoint is executed, flagr will scan the migration files, insert them into the db and output status | ||
|
||
### Config | ||
Location of yaml configs is set by env var before running the server | ||
``` | ||
FLAGR_MIGRATION_PATH=./migrations/ | ||
./flagr | ||
``` |
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
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.