File: column-time-precision-maria.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 (49 lines) | stat: -rw-r--r-- 1,196 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
# Each test runs on a clean database.
only maria*

# Apply schema "1.hcl" on fresh database.
apply 1.hcl

# Compare the result of "SHOW TABLE users" with the content of a file named '1.sql'.
cmpshow foo 1.sql

# Files
-- 1.hcl --
schema "$db" {}

table "foo" {
  schema    = schema.$db
  column "id" {
    null = false
    type = char(36)
  }
  column "precision_default" {
    null      = false
    type      = timestamp
    default   = sql("CURRENT_TIMESTAMP")
    on_update = sql("CURRENT_TIMESTAMP")
  }
  column "create_time" {
    null    = false
    type    = timestamp(6)
    default = sql("CURRENT_TIMESTAMP(6)")
  }
  column "update_time" {
    null    = false
    type    = datetime(6)
    default = sql("CURRENT_TIMESTAMP(6)")
    on_update = sql("CURRENT_TIMESTAMP(6)")
  }
  primary_key {
    columns = [table.foo.column.id, ]
  }
}

-- 1.sql --
CREATE TABLE `foo` (
  `id` char(36) NOT NULL,
  `precision_default` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `create_time` timestamp(6) NOT NULL DEFAULT current_timestamp(6),
  `update_time` datetime(6) NOT NULL DEFAULT current_timestamp(6) ON UPDATE current_timestamp(6),
  PRIMARY KEY (`id`)
)