File: cli-migrate-diff.txt

package info (click to toggle)
golang-ariga-atlas 0.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 5,676 kB
  • sloc: javascript: 592; sql: 404; makefile: 10
file content (56 lines) | stat: -rw-r--r-- 1,188 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
exec mkdir migrations

! atlas migrate diff --to file://1.hcl --dir file://migrations
stderr '"dev-url" not set'

! atlas migrate diff --dev-url postgres://devdb --dir file://migrations
stderr '"to" not set'

atlas migrate diff --dev-url URL --to file://./1.hcl first
cmpmig 0 1.sql

atlas migrate diff --dev-url URL --to file://./2.hcl second
cmpmig 1 2.sql

-- 1.hcl --
schema "script_cli_migrate_diff" {}

table "users" {
  schema = schema.script_cli_migrate_diff
  column "id" {
    null = false
    type = bigint
    auto_increment = true
  }
  primary_key  {
    columns = [column.id]
  }
}

-- 1.sql --
-- create "users" table
CREATE TABLE "users" ("id" bigint NOT NULL, PRIMARY KEY ("id"));

-- 2.hcl --
schema "script_cli_migrate_diff" {}

table "users" {
  schema = schema.script_cli_migrate_diff
  column "id" {
    null = false
    type = bigint
    auto_increment = true
  }
  column "create_time" {
    null    = false
    type    = timestamp(4)
    default = sql("CURRENT_TIMESTAMP(4)")
  }
  primary_key  {
    columns = [column.id]
  }
}

-- 2.sql --
-- modify "users" table
ALTER TABLE "users" ADD COLUMN "create_time" timestamp(4) NOT NULL DEFAULT CURRENT_TIMESTAMP(4);