본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

데이터베이스 마이그레이션 (Database Migrations)

원문 보기 위키 갱신

이 페이지는 Argo Workflows가 시작 시점에 자동으로 적용하는 SQL 마이그레이션 목록을 정리한 문서입니다. 마이그레이션은 증분 방식으로 적용되며 버전 테이블로 추적되고, 각 마이그레이션은 단 한 번만 실행됩니다.

출처: Argo Workflows 문서

본문

이 페이지는 Argo Workflows가 시작할 때 자동으로 적용하는 SQL 마이그레이션을 나열합니다. 마이그레이션은 증분 방식으로 적용되며 버전 테이블로 추적됩니다. 각 마이그레이션은 한 번만 실행됩니다. 항목의 순서를 바꾸거나 제거하지 마세요.

여기 보이는 테이블 이름과 클러스터 이름은 기본값입니다. 실제 배포 환경에서는 설정에 따라 다른 값을 사용할 수 있습니다.

설정 세부 사항은 Workflow Archive와 Synchronization 문서를 참고하세요.

Steps(단계)

각 마이그레이션은 Step이라는 번호로 식별됩니다. Argo Workflows가 컨트롤러 시작 시 자동 마이그레이션을 실행하면, 적용된 가장 높은 스텝 번호를 버전 테이블(아카이브 데이터베이스는 schema_history, 동기화(sync) 데이터베이스는 sync_schema_history)에 기록하고, 이후 시작할 때는 그보다 번호가 큰 스텝만 실행합니다. 데이터베이스 종류에 따라 아무 것도 하지 않는 스텝은 존재하지 않을 수 있습니다. 따라서 스텝의 순서를 바꾸거나 제거해서는 절대 안 됩니다 - 새로운 스키마 변경은 항상 새로운 스텝으로 추가됩니다.

이 문들을 직접 실행한다면(예를 들어 skipMigration: true를 설정했거나 스키마를 수동으로 만들고 싶은 경우), 데이터베이스가 어느 스텝까지 도달했는지 추적하는 것은 여러분의 책임입니다. Argo Workflows는 부분적으로 수동 적용된 상태를 감지하지 못합니다 - 버전 테이블만 읽기 때문입니다. 버전 테이블이 실제 스키마와 어긋나 있으면 컨트롤러가 이미 적용된 스텝을 다시 적용하다가 실패하거나, 여러분이 실행하지 않은 스텝을 건너뛸 수 있습니다.

프로그래매틱(programmatic) 마이그레이션은 여기서 다루지 않으므로, 해당 스텝은 코드를 직접 확인해야 합니다.

아카이브 데이터베이스 (Archive Database)

MySQL

-- Step 0
create table if not exists argo_workflows (
    id varchar(128) ,
    name varchar(256),
    phase varchar(25),
    namespace varchar(256),
    workflow text,
    startedat timestamp default CURRENT_TIMESTAMP,
    finishedat timestamp default CURRENT_TIMESTAMP,
    creationtimestamp timestamp default CURRENT_TIMESTAMP,
    primary key (id, namespace)
);

-- Step 1
create unique index idx_name on argo_workflows (name);

-- Step 2
create table if not exists argo_workflow_history (
    id varchar(128) ,
    name varchar(256),
    phase varchar(25),
    namespace varchar(256),
    workflow text,
    startedat timestamp default CURRENT_TIMESTAMP,
    finishedat timestamp default CURRENT_TIMESTAMP,
    primary key (id, namespace)
);

-- Step 3
alter table argo_workflow_history rename to argo_archived_workflows;

-- Step 4
drop index idx_name on argo_workflows;

-- Step 5
create unique index idx_name on argo_workflows(name, namespace);

-- Step 6
alter table argo_workflows drop primary key;

-- Step 7
alter table argo_workflows add primary key(name,namespace);

-- Step 8
alter table argo_archived_workflows drop primary key;

-- Step 9
alter table argo_archived_workflows add primary key(id);

-- Step 10
alter table argo_archived_workflows change column id uid varchar(128);

-- Step 11
alter table argo_archived_workflows modify column uid varchar(128) not null;

-- Step 12
alter table argo_archived_workflows modify column phase varchar(25) not null;

-- Step 13
alter table argo_archived_workflows modify column namespace varchar(256) not null;

-- Step 14
alter table argo_archived_workflows modify column workflow text not null;

-- Step 15
alter table argo_archived_workflows modify column startedat timestamp not null default CURRENT_TIMESTAMP;

-- Step 16
alter table argo_archived_workflows modify column finishedat timestamp not null default CURRENT_TIMESTAMP;

-- Step 17
alter table argo_archived_workflows add clustername varchar(64);

-- Step 18
update argo_archived_workflows set clustername = '<cluster-name>' where clustername is null;

-- Step 19
alter table argo_archived_workflows modify column clustername varchar(64) not null;

-- Step 20
alter table argo_archived_workflows drop primary key;

-- Step 21
alter table argo_archived_workflows add primary key(clustername,uid);

-- Step 22
create index argo_archived_workflows_i1 on argo_archived_workflows (clustername,namespace);

-- Step 23
alter table argo_workflows drop column phase;

-- Step 24
alter table argo_workflows drop column startedat;

-- Step 25
alter table argo_workflows drop column finishedat;

-- Step 26
alter table argo_workflows change column id uid varchar(128);

-- Step 27
alter table argo_workflows modify column uid varchar(128) not null;

-- Step 28
alter table argo_workflows modify column namespace varchar(256) not null;

-- Step 29
alter table argo_workflows add column clustername varchar(64);

-- Step 30
update argo_workflows set clustername = '<cluster-name>' where clustername is null;

-- Step 31
alter table argo_workflows modify column clustername varchar(64) not null;

-- Step 32
alter table argo_workflows add column version varchar(64);

-- Step 33
alter table argo_workflows add column nodes text;

-- Step 34
— *Programmatic migration: backfillNodes{argo_workflows}*

-- Step 35
alter table argo_workflows modify column nodes text not null;

-- Step 36
alter table argo_workflows drop column workflow;

-- Step 37
alter table argo_workflows add column updatedat timestamp not null default current_timestamp;

-- Step 38
alter table argo_workflows drop primary key;

-- Step 39
drop index idx_name on argo_workflows;

-- Step 40
alter table argo_workflows drop column name;

-- Step 41
alter table argo_workflows add primary key(clustername,uid,version);

-- Step 42
create index argo_workflows_i1 on argo_workflows (clustername,namespace);

-- Step 43
alter table argo_archived_workflows modify column workflow json not null;

-- Step 44
alter table argo_archived_workflows modify column name varchar(256) not null;

-- Step 45
create index argo_workflows_i2 on argo_workflows (clustername,namespace,updatedat);

-- Step 46
create table if not exists argo_archived_workflows_labels (
	clustername varchar(64) not null,
	uid varchar(128) not null,
    name varchar(317) not null,
    value varchar(63) not null,
    primary key (clustername, uid, name),
 	foreign key (clustername, uid) references argo_archived_workflows(clustername, uid) on delete cascade
);

-- Step 47
alter table argo_workflows modify column nodes json not null;

-- Step 48
alter table argo_archived_workflows add column instanceid varchar(64);

-- Step 49
update argo_archived_workflows set instanceid = '' where instanceid is null;

-- Step 50
alter table argo_archived_workflows modify column instanceid varchar(64) not null;

-- Step 51
drop index argo_archived_workflows_i1 on argo_archived_workflows;

-- Step 52
create index argo_archived_workflows_i1 on argo_archived_workflows (clustername,instanceid,namespace);

-- Step 53
drop index argo_workflows_i1 on argo_workflows;

-- Step 54
drop index argo_workflows_i2 on argo_workflows;

-- Step 55
create index argo_workflows_i1 on argo_workflows (clustername,namespace,updatedat);

-- Step 56
create index argo_archived_workflows_i2 on argo_archived_workflows (clustername,instanceid,finishedat);

-- Step 57
create index argo_archived_workflows_i3 on argo_archived_workflows (clustername,instanceid,name);

-- Step 58
create index argo_archived_workflows_i4 on argo_archived_workflows (startedat);

-- Step 59
create index argo_archived_workflows_labels_i1 on argo_archived_workflows_labels (name,value);

-- Step 61
drop index argo_archived_workflows_i4 on argo_archived_workflows;

-- Step 62
create index argo_archived_workflows_i4 on argo_archived_workflows (clustername, startedat);

-- Step 63
alter table argo_archived_workflows add column creationtimestamp timestamp null;

-- Step 64
update argo_archived_workflows set creationtimestamp = startedat where creationtimestamp is null;

-- Step 65
alter table argo_archived_workflows modify column creationtimestamp timestamp not null default CURRENT_TIMESTAMP;

-- Step 66
create index argo_archived_workflows_i5 on argo_archived_workflows (creationtimestamp);

-- Step 67
drop index argo_archived_workflows_i1 on argo_archived_workflows;

-- Step 68
create index argo_archived_workflows_i1 on argo_archived_workflows (clustername, instanceid, namespace, startedat DESC);

PostgreSQL

-- Step 0
create table if not exists argo_workflows (
    id varchar(128) ,
    name varchar(256),
    phase varchar(25),
    namespace varchar(256),
    workflow text,
    startedat timestamp default CURRENT_TIMESTAMP,
    finishedat timestamp default CURRENT_TIMESTAMP,
    creationtimestamp timestamp default CURRENT_TIMESTAMP,
    primary key (id, namespace)
);

-- Step 1
create unique index idx_name on argo_workflows (name);

-- Step 2
create table if not exists argo_workflow_history (
    id varchar(128) ,
    name varchar(256),
    phase varchar(25),
    namespace varchar(256),
    workflow text,
    startedat timestamp default CURRENT_TIMESTAMP,
    finishedat timestamp default CURRENT_TIMESTAMP,
    primary key (id, namespace)
);

-- Step 3
alter table argo_workflow_history rename to argo_archived_workflows;

-- Step 4
drop index idx_name;

-- Step 5
create unique index idx_name on argo_workflows(name, namespace);

-- Step 6
alter table argo_workflows drop constraint argo_workflows_pkey;

-- Step 7
alter table argo_workflows add primary key(name,namespace);

-- Step 8
alter table argo_archived_workflows drop constraint argo_workflow_history_pkey;

-- Step 9
alter table argo_archived_workflows add primary key(id);

-- Step 10
alter table argo_archived_workflows rename column id to uid;

-- Step 11
alter table argo_archived_workflows alter column uid set not null;

-- Step 12
alter table argo_archived_workflows alter column phase set not null;

-- Step 13
alter table argo_archived_workflows alter column namespace set not null;

-- Step 14
alter table argo_archived_workflows alter column workflow set not null;

-- Step 15
alter table argo_archived_workflows alter column startedat set not null;

-- Step 16
alter table argo_archived_workflows alter column finishedat set not null;

-- Step 17
alter table argo_archived_workflows add clustername varchar(64);

-- Step 18
update argo_archived_workflows set clustername = '<cluster-name>' where clustername is null;

-- Step 19
alter table argo_archived_workflows alter column clustername set not null;

-- Step 20
alter table argo_archived_workflows drop constraint argo_archived_workflows_pkey;

-- Step 21
alter table argo_archived_workflows add primary key(clustername,uid);

-- Step 22
create index argo_archived_workflows_i1 on argo_archived_workflows (clustername,namespace);

-- Step 23
alter table argo_workflows drop column phase;

-- Step 24
alter table argo_workflows drop column startedat;

-- Step 25
alter table argo_workflows drop column finishedat;

-- Step 26
alter table argo_workflows rename column id to uid;

-- Step 27
alter table argo_workflows alter column uid set not null;

-- Step 28
alter table argo_workflows alter column namespace set not null;

-- Step 29
alter table argo_workflows add column clustername varchar(64);

-- Step 30
update argo_workflows set clustername = '<cluster-name>' where clustername is null;

-- Step 31
alter table argo_workflows alter column clustername set not null;

-- Step 32
alter table argo_workflows add column version varchar(64);

-- Step 33
alter table argo_workflows add column nodes text;

-- Step 34
— *Programmatic migration: backfillNodes{argo_workflows}*

-- Step 35
alter table argo_workflows alter column nodes set not null;

-- Step 36
alter table argo_workflows drop column workflow;

-- Step 37
alter table argo_workflows add column updatedat timestamp not null default current_timestamp;

-- Step 38
alter table argo_workflows drop constraint argo_workflows_pkey;

-- Step 39
drop index idx_name;

-- Step 40
alter table argo_workflows drop column name;

-- Step 41
alter table argo_workflows add primary key(clustername,uid,version);

-- Step 42
create index argo_workflows_i1 on argo_workflows (clustername,namespace);

-- Step 43
alter table argo_archived_workflows alter column workflow type json using workflow::json;

-- Step 44
alter table argo_archived_workflows alter column name set not null;

-- Step 45
create index argo_workflows_i2 on argo_workflows (clustername,namespace,updatedat);

-- Step 46
create table if not exists argo_archived_workflows_labels (
	clustername varchar(64) not null,
	uid varchar(128) not null,
    name varchar(317) not null,
    value varchar(63) not null,
    primary key (clustername, uid, name),
 	foreign key (clustername, uid) references argo_archived_workflows(clustername, uid) on delete cascade
);

-- Step 47
alter table argo_workflows alter column nodes type json using nodes::json;

-- Step 48
alter table argo_archived_workflows add column instanceid varchar(64);

-- Step 49
update argo_archived_workflows set instanceid = '' where instanceid is null;

-- Step 50
alter table argo_archived_workflows alter column instanceid set not null;

-- Step 51
drop index argo_archived_workflows_i1;

-- Step 52
create index argo_archived_workflows_i1 on argo_archived_workflows (clustername,instanceid,namespace);

-- Step 53
drop index argo_workflows_i1;

-- Step 54
drop index argo_workflows_i2;

-- Step 55
create index argo_workflows_i1 on argo_workflows (clustername,namespace,updatedat);

-- Step 56
create index argo_archived_workflows_i2 on argo_archived_workflows (clustername,instanceid,finishedat);

-- Step 57
create index argo_archived_workflows_i3 on argo_archived_workflows (clustername,instanceid,name);

-- Step 58
create index argo_archived_workflows_i4 on argo_archived_workflows (startedat);

-- Step 59
create index argo_archived_workflows_labels_i1 on argo_archived_workflows_labels (name,value);

-- Step 60
alter table argo_archived_workflows alter column workflow set data type jsonb using workflow::jsonb;

-- Step 61
drop index argo_archived_workflows_i4;

-- Step 62
create index argo_archived_workflows_i4 on argo_archived_workflows (clustername, startedat);

-- Step 63
alter table argo_archived_workflows add column creationtimestamp timestamp null;

-- Step 64
update argo_archived_workflows set creationtimestamp = startedat where creationtimestamp is null;

-- Step 65
alter table argo_archived_workflows alter column creationtimestamp set default CURRENT_TIMESTAMP;

-- Step 66
create index argo_archived_workflows_i5 on argo_archived_workflows (creationtimestamp);

-- Step 67
drop index argo_archived_workflows_i1;

-- Step 68
create index argo_archived_workflows_i1 on argo_archived_workflows (clustername, instanceid, namespace, startedat DESC);

동기화 데이터베이스 (Sync Database)

MySQL

-- Step 0
create table if not exists sync_limit (
    name varchar(256) not null,
    sizelimit int,
    primary key (name)
);

-- Step 1
create unique index ilimit_name on sync_limit (name);

-- Step 2
create table if not exists sync_controller (
    controller varchar(64) not null,
    time timestamp,
    primary key (controller)
);

-- Step 3
create unique index icontroller_name on sync_controller (controller);

-- Step 4
create table if not exists sync_state (
    name varchar(256),
    workflowkey varchar(256),
    controller varchar(64) not null,
    held boolean,
    priority int,
    time timestamp,
    primary key(name, workflowkey, controller)
);

-- Step 5
create index istate_name on sync_state (name);

-- Step 6
create index istate_workflowkey on sync_state (workflowkey);

-- Step 7
create index istate_controller on sync_state (controller);

-- Step 8
create index istate_held on sync_state (held);

-- Step 9
create table if not exists sync_lock (
    name varchar(256),
    controller varchar(64) not null,
    time timestamp,
    primary key(name)
);

-- Step 10
create unique index ilock_name on sync_lock (name);

PostgreSQL

-- Step 0
create table if not exists sync_limit (
    name varchar(256) not null,
    sizelimit int,
    primary key (name)
);

-- Step 1
create unique index ilimit_name on sync_limit (name);

-- Step 2
create table if not exists sync_controller (
    controller varchar(64) not null,
    time timestamp,
    primary key (controller)
);

-- Step 3
create unique index icontroller_name on sync_controller (controller);

-- Step 4
create table if not exists sync_state (
    name varchar(256),
    workflowkey varchar(256),
    controller varchar(64) not null,
    held boolean,
    priority int,
    time timestamp,
    primary key(name, workflowkey, controller)
);

-- Step 5
create index istate_name on sync_state (name);

-- Step 6
create index istate_workflowkey on sync_state (workflowkey);

-- Step 7
create index istate_controller on sync_state (controller);

-- Step 8
create index istate_held on sync_state (held);

-- Step 9
create table if not exists sync_lock (
    name varchar(256),
    controller varchar(64) not null,
    time timestamp,
    primary key(name)
);

-- Step 10
create unique index ilock_name on sync_lock (name);

더 알아보기 (Learn more)

  • 마이그레이션 스텝은 절대 재정렬하거나 제거하면 안 되며, 새 변경은 항상 새 스텝으로 추가됩니다. 버전 테이블만이 적용 이력의 유일한 근거입니다.
  • skipMigration: true로 수동 마이그레이션을 선택하면 스텝 추적 책임도 함께 넘어옵니다. 부분 적용은 자동으로 감지되지 않습니다.
  • 프로그래매틱 마이그레이션(예: backfillNodes)은 이 문서에 없으므로 해당 스텝은 소스 코드를 확인해야 합니다.