mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-11 00:08:30 +01:00
feat: promote toggles script (#3639)
This commit is contained in:
parent
b18d62521f
commit
116db8f6d1
52
scripts/promote.sh
Executable file
52
scripts/promote.sh
Executable file
@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Source Unleash instance
|
||||
SOURCE_URL=""
|
||||
SOURCE_API_TOKEN=""
|
||||
SOURCE_ENV="production"
|
||||
SOURCE_TAG="exported"
|
||||
|
||||
# Target Unleash instance
|
||||
TARGET_URL=""
|
||||
TARGET_API_TOKEN=""
|
||||
TARGET_PROJECT="DemoImport"
|
||||
TARGET_ENV="production"
|
||||
|
||||
export_data() {
|
||||
curl -s -w "\n%{http_code}" -X POST "$SOURCE_URL" \
|
||||
-H "Authorization: $SOURCE_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"tag\": \"$SOURCE_TAG\", \"environment\": \"$SOURCE_ENV\"}"
|
||||
}
|
||||
|
||||
import_data() {
|
||||
data="$1"
|
||||
response=$(curl -s -w "\n%{http_code}" -X POST "$TARGET_URL" \
|
||||
-H "Authorization: $TARGET_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"project\": \"$TARGET_PROJECT\", \"environment\": \"$TARGET_ENV\", \"data\": $data}")
|
||||
|
||||
http_code=$(echo "$response" | awk 'END{print}')
|
||||
|
||||
if ! [[ $http_code -ge 200 && $http_code -lt 300 ]]; then
|
||||
status_message=$(echo "$response" | awk 'NR==1{print}')
|
||||
echo "Error: Import failed with $http_code $status_message"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
echo "Exporting data from source API: ${SOURCE_URL}, tag: ${SOURCE_TAG}, environment: ${SOURCE_ENV}"
|
||||
response=$(export_data)
|
||||
http_code=$(echo "$response" | awk 'END{print}')
|
||||
if [[ $http_code -ge 200 && $http_code -lt 300 ]]; then
|
||||
data=$(echo "$response" | awk 'NR>1{print line} {line=$0}')
|
||||
echo "Data exported successfully."
|
||||
else
|
||||
status_message=$(echo "$response" | awk 'NR==1{print}')
|
||||
echo "Error: Export failed with $http_code $status_message"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Importing data to target API: ${TARGET_URL}, project: ${TARGET_PROJECT}, environment: ${TARGET_ENV}"
|
||||
import_data "$data"
|
||||
echo "Data imported successfully."
|
@ -39,6 +39,7 @@ export class ImportTogglesStore implements IImportTogglesStore {
|
||||
featureNames: string[],
|
||||
environment: string,
|
||||
): Promise<boolean> {
|
||||
if (featureNames.length === 0) return true;
|
||||
const result = await this.db.raw(
|
||||
'SELECT EXISTS (SELECT 1 FROM feature_strategies WHERE environment = ? and feature_name in (' +
|
||||
featureNames.map(() => '?').join(',') +
|
||||
|
Loading…
Reference in New Issue
Block a user