File: column-generated.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 (120 lines) | stat: -rw-r--r-- 2,122 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
apply 1.hcl
cmpshow users 1.sql

# Insert a few records to the table, and check the
# migration process using a temporary table.
execsql 'INSERT INTO users (a) VALUES (1), (2), (3)'

apply 2.hcl
cmpshow users 2.sql

apply 3.hcl
cmpshow users 3.sql

# Appending a new VIRTUAL column should use ALTER command.
apply 4.hcl
cmpshow users 4.sql


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

table "users" {
    schema = schema.main
    column "a" {
        type = int
    }
    column "b" {
        type = int
        as = "1"
    }
    column "c" {
        type = int
        as {
            expr = "2"
            type = STORED
        }
    }
}

-- 1.sql --
CREATE TABLE `users` (`a` int NOT NULL, `b` int NOT NULL AS (1) VIRTUAL, `c` int NOT NULL AS (2) STORED)

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

table "users" {
    schema = schema.main
    column "a" {
        type = int
    }
    column "b" {
        type = int
        as = "1"
    }
    column "c" {
        type = int
        as {
            expr = "2"
            type = VIRTUAL
        }
    }
}

-- 2.sql --
CREATE TABLE "users" (`a` int NOT NULL, `b` int NOT NULL AS (1) VIRTUAL, `c` int NOT NULL AS (2) VIRTUAL)

-- 3.hcl --
schema "main" {}

table "users" {
    schema = schema.main
    column "a" {
        type = int
    }
    column "b" {
        type = int
        as = "2"
    }
    column "c" {
        type = int
        as {
            expr = "3"
            type = VIRTUAL
        }
    }
}

-- 3.sql --
CREATE TABLE "users" (`a` int NOT NULL, `b` int NOT NULL AS (2) VIRTUAL, `c` int NOT NULL AS (3) VIRTUAL)

-- 4.hcl --
schema "main" {}

table "users" {
    schema = schema.main
    column "a" {
        type = int
    }
    column "b" {
        type = int
        as = "2"
    }
    column "c" {
        type = int
        as {
            expr = "3"
            type = VIRTUAL
        }
    }
    column "d" {
        type = int
        as {
            expr = "4"
            type = VIRTUAL
        }
    }
}

-- 4.sql --
CREATE TABLE "users" (`a` int NOT NULL, `b` int NOT NULL AS (2) VIRTUAL, `c` int NOT NULL AS (3) VIRTUAL, `d` int NOT NULL AS (4) VIRTUAL)