Skip to content
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

chore: enable version-specific db migration #453

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/go-redis/redis v6.15.9+incompatible
github.com/go-sql-driver/mysql v1.7.1
github.com/golang-migrate/migrate/v4 v4.11.0
github.com/golang-migrate/migrate/v4 v4.16.0
github.com/golang/protobuf v1.5.3
github.com/gomodule/redigo v2.0.0+incompatible
github.com/google/go-cmp v0.5.9
Expand Down Expand Up @@ -79,8 +79,8 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/flatbuffers v2.0.8+incompatible // indirect
github.com/google/go-github v17.0.0+incompatible // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/go-github/v39 v39.2.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/pprof v0.0.0-20221103000818-d260c55eee4c // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
Expand All @@ -107,10 +107,10 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/tools v0.9.1 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
172 changes: 19 additions & 153 deletions go.sum

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions manifests/bucketeer/charts/migration-mysql/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
5 changes: 5 additions & 0 deletions manifests/bucketeer/charts/migration-mysql/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for bucketeer-migration-mysql
name: migration-mysql
version: 1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "migration-mysql.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "migration-mysql.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "migration-mysql.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{- define "service-cert-secret" -}}
{{- if .Values.tls.service.secret }}
{{- printf "%s" .Values.tls.service.secret -}}
{{- else -}}
{{ template "migration-mysql.fullname" . }}-service-cert
{{- end -}}
{{- end -}}

{{- define "service-token-secret" -}}
{{- if .Values.serviceToken.secret }}
{{- printf "%s" .Values.serviceToken.secret -}}
{{- else -}}
{{ template "migration-mysql.fullname" . }}-service-token
{{- end -}}
{{- end -}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: batch/v1
kind: Job
metadata:
name: migration-mysql-{{ .Values.global.image.tag }}
labels:
app: migration-mysql-{{ .Values.global.image.tag }}
chart: {{ template "migration-mysql.chart" . }}
release: {{ template "migration-mysql.fullname" . }}
heritage: {{ .Release.Service }}
spec:
template:
metadata:
labels:
app: migration-mysql-{{ .Values.global.image.tag }}
release: {{ template "migration-mysql.fullname" . }}
spec:
restartPolicy: Never
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /bin/sh
args:
- -c
- |
echo "START automatic migration mysql."
ENDPOINT="https://web-gateway.{{ .Values.namespace }}.svc.cluster.local:{{ .Values.webGatewayPort }}/bucketeer.migration.MigrationMySQLService/MigrateAllMasterSchema"
TOKEN=`cat /usr/local/service-token/token`
RES=`curl -X POST --cacert /usr/local/certs/service/tls.crt -m 300 ${ENDPOINT} -H "authorization: bearer ${TOKEN}" -H "Content-Type: application/json" -s -o /dev/null -w '%{http_code}\\n'`
echo "response = "${RES}
echo "END automatic migration mysql."
volumeMounts:
- name: service-cert-secret
mountPath: /usr/local/certs/service
readOnly: true
- name: service-token-secret
mountPath: /usr/local/service-token
readOnly: true
volumes:
- name: service-cert-secret
secret:
secretName: {{ template "service-cert-secret" . }}
- name: service-token-secret
secret:
secretName: {{ template "service-token-secret" . }}
backoffLimit: 0
completions: 1
parallelism: 1
ttlSecondsAfterFinished: {{ .Values.ttlSecondsAfterFinished }}
18 changes: 18 additions & 0 deletions manifests/bucketeer/charts/migration-mysql/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
image:
repository: curlimages/curl
tag: 8.1.2
pullPolicy: IfNotPresent

fullnameOverride: "migration-mysql"

namespace: default

webGatewayPort: 9000
ttlSecondsAfterFinished: 60

tls:
service:
secret:

serviceToken:
secret:
23 changes: 23 additions & 0 deletions migrations/mysql/1687512689_initialize_schema.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
DROP TABLE IF EXISTS `account`;
DROP TABLE IF EXISTS `admin_account`;
DROP TABLE IF EXISTS `admin_audit_log`;
DROP TABLE IF EXISTS `admin_subscription`;
DROP TABLE IF EXISTS `api_key`;
DROP TABLE IF EXISTS `audit_log`;
DROP TABLE IF EXISTS `auto_ops_rule`;
DROP TABLE IF EXISTS `environment`;
DROP TABLE IF EXISTS `experiment`;
DROP TABLE IF EXISTS `experiment_result`;
DROP TABLE IF EXISTS `feature`;
DROP TABLE IF EXISTS `feature_last_used_info`;
DROP TABLE IF EXISTS `goal`;
DROP TABLE IF EXISTS `mau`;
DROP TABLE IF EXISTS `ops_count`;
DROP TABLE IF EXISTS `ops_progressive_rollout`;
DROP TABLE IF EXISTS `project`;
DROP TABLE IF EXISTS `push`;
DROP TABLE IF EXISTS `segment`;
DROP TABLE IF EXISTS `segment_user`;
DROP TABLE IF EXISTS `subscription`;
DROP TABLE IF EXISTS `tag`;
DROP TABLE IF EXISTS `webhook`;
Loading
Loading