amacneil / amacneil/dbmate

Error on multiple migrations in a single file

Aberta
#820 1 comentário 0 reações 0 responsáveis Ver no GitHub
bug
Linguagem predominante
Go
Estrelas
7.4k
Forks
380
Merge médio
1d 16h
PRs com merge (30d)
2

Descrição

**Description**

Using multiple migrations in a single file using additional migrate:up and migrate:down sections, I get the error:

Error: pq: duplicate key value violates unique constraint "schema_migrations_pkey" (23505)

Moreover, the file containing multiple migrations is reported as applied in `dbmate status`. In reality, only the first migration (`-- migrate:up` block) is applied.

- Version: 2.34.1
- Database: PostgreSQL
- Operating System: Debian

**Steps To Reproduce**

1. Use this migration file:

```sql
-- migrate:up
CREATE TABLE t1 (
col_a text
);

-- migrate:down
DROP TABLE t1;

-- migrate:up
CREATE TABLE t2 (
col_b text
);

-- migrate:down
DROP TABLE t2;
```

2. Run `dbmate migrate`

**Expected Behavior**

Successful migration

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Direção de pesquisa

Use the SQL migration in the reproduction steps as the starting fixture; first run `dbmate migrate` and inspect the migration parsing and application path used by the `dbmate` entry point. Done means both tables are applied from one file without the duplicate-key error, and `dbmate status` reports the file accurately.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
go, postgresql
Domínio
cli, databases
Tipo de issue
Bug
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Ativa
Clareza
Claramente especificada
Facilidade para iniciantes
68/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.