-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added flag migrations as yaml #583
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 test@test.com | ||
rank: 0 | ||
rolloutPercent: 100 | ||
constraints: | ||
- property: email | ||
operator: EQ | ||
value: '"test@test.com"' | ||
distributions: | ||
- variantKey: "on" | ||
percent: 100 | ||
- rank: 1 | ||
rolloutPercent: 100 | ||
constraints: [] | ||
distributions: | ||
- variantKey: "off" | ||
percent: 100 | ||
variants: | ||
- key: "off" | ||
attachment: {} | ||
- key: "on" | ||
attachment: {} | ||
entityType: User | ||
pixeldrew marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, if it's GET, should this be something like getMigrations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I was a little unsure on this, i'm using this as endpoint to run the migration process. It will only run the migrations if finds new files in the directory