Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8bcc2a1

Browse files
committed
fix: stringify struct defaults in migration generator
1 parent04190e1 commit8bcc2a1

File tree

4 files changed

+142
-5
lines changed

4 files changed

+142
-5
lines changed

‎lib/migration_generator/migration_generator.ex‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,9 +1630,18 @@ defmodule AshPostgres.MigrationGenerator do
16301630

16311631
defpdefault(%{default:value,type:type},_)do
16321632
caseAsh.Type.dump_to_native(type,value)do
1633-
{:ok,value}->inspect(value)
1634-
_->"nil"
1633+
{:ok,value}whenis_struct(value)->
1634+
to_string(value)
1635+
1636+
{:ok,value}->
1637+
inspect(value)
1638+
1639+
_->
1640+
"nil"
16351641
end
1642+
rescue
1643+
_->
1644+
"nil"
16361645
end
16371646

16381647
defpsnapshot_to_binary(snapshot)do
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"attributes": [
3+
{
4+
"allow_nil?":true,
5+
"default":"nil",
6+
"generated?":false,
7+
"name":"category",
8+
"primary_key?":false,
9+
"references":null,
10+
"type":"citext"
11+
},
12+
{
13+
"allow_nil?":true,
14+
"default":"0",
15+
"generated?":false,
16+
"name":"decimal",
17+
"primary_key?":false,
18+
"references":null,
19+
"type":"decimal"
20+
},
21+
{
22+
"allow_nil?":false,
23+
"default":"fragment(\"uuid_generate_v4()\")",
24+
"generated?":false,
25+
"name":"id",
26+
"primary_key?":true,
27+
"references":null,
28+
"type":"uuid"
29+
},
30+
{
31+
"allow_nil?":true,
32+
"default":"nil",
33+
"generated?":false,
34+
"name":"price",
35+
"primary_key?":false,
36+
"references":null,
37+
"type":"bigint"
38+
},
39+
{
40+
"allow_nil?":true,
41+
"default":"nil",
42+
"generated?":false,
43+
"name":"public",
44+
"primary_key?":false,
45+
"references":null,
46+
"type":"boolean"
47+
},
48+
{
49+
"allow_nil?":true,
50+
"default":"nil",
51+
"generated?":false,
52+
"name":"score",
53+
"primary_key?":false,
54+
"references":null,
55+
"type":"bigint"
56+
},
57+
{
58+
"allow_nil?":true,
59+
"default":"nil",
60+
"generated?":false,
61+
"name":"status",
62+
"primary_key?":false,
63+
"references":null,
64+
"type":"status"
65+
},
66+
{
67+
"allow_nil?":true,
68+
"default":"nil",
69+
"generated?":false,
70+
"name":"title",
71+
"primary_key?":false,
72+
"references":null,
73+
"type":"text"
74+
},
75+
{
76+
"allow_nil?":true,
77+
"default":"\"sponsored\"",
78+
"generated?":false,
79+
"name":"type",
80+
"primary_key?":false,
81+
"references":null,
82+
"type":"text"
83+
}
84+
],
85+
"base_filter":"type = 'sponsored'",
86+
"check_constraints": [
87+
{
88+
"attribute": [
89+
"price"
90+
],
91+
"base_filter":"type = 'sponsored'",
92+
"check":"price > 0",
93+
"name":"price_must_be_positive"
94+
}
95+
],
96+
"has_create_action":true,
97+
"hash":"42B75BE079D8BBC3AE0EC4B1517A4D0E150F381E9817F9D8FA53E1E689A80D3B",
98+
"identities": [],
99+
"multitenancy": {
100+
"attribute":null,
101+
"global":null,
102+
"strategy":null
103+
},
104+
"repo":"Elixir.AshPostgres.TestRepo",
105+
"table":"posts"
106+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
defmoduleAshPostgres.TestRepo.Migrations.MigrateResources9do
2+
@moduledoc"""
3+
Updates resources based on their most recent snapshots.
4+
5+
This file was autogenerated with `mix ash_postgres.generate_migrations`
6+
"""
7+
8+
useEcto.Migration
9+
10+
defupdo
11+
altertable(:posts)do
12+
add:decimal,:decimal,default:0
13+
end
14+
end
15+
16+
defdowndo
17+
altertable(:posts)do
18+
remove:decimal
19+
end
20+
end
21+
end

‎test/support/resources/post.ex‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ defmodule AshPostgres.Test.Post do
44
data_layer:AshPostgres.DataLayer
55

66
postgresdo
7-
table"posts"
8-
repoAshPostgres.TestRepo
9-
base_filter_sql"type = 'sponsored'"
7+
table("posts")
8+
repo(AshPostgres.TestRepo)
9+
base_filter_sql("type = 'sponsored'")
1010

1111
check_constraintsdo
1212
check_constraint(:price,"price_must_be_positive",
@@ -44,6 +44,7 @@ defmodule AshPostgres.Test.Post do
4444
attribute(:category,:ci_string)
4545
attribute(:type,:atom,default::sponsored,private?:true,writable?:false)
4646
attribute(:price,:integer)
47+
attribute(:decimal,:decimal,default:Decimal.new(0))
4748
attribute(:status,AshPostgres.Test.Types.Status)
4849
end
4950

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp