Commit 3c4ff4f
committed
fix(sqlite): allow to use overrides for columns which were created using "alter table .. add column"
This fixes the failing test which was added in the previous commit.
Normalize sqlite `ALTER TABLE` column identifiers and preserve analyzer
origin metadata when merging query analysis. This allows exact column
overrides such as `chat_messages.updated_at` to match columns added via
`ALTER TABLE .. ADD COLUMN`.
Using the sqlc config:
overrides:
- column: "*.*_at"
go_type:
import: "time"
type: "Time"
and the SQL schema:
CREATE TABLE chat_messages (
id TEXT PRIMARY KEY NOT NULL,
body TEXT NOT NULL,
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
) STRICT;
ALTER TABLE chat_messages ADD COLUMN "updated_at" TEXT NOT NULL DEFAULT '';
sqlc would previously generate the following code:
type ChatMessage struct {
ID string
Body string
CreatedAt time.Time
UpdatedAt string // Bug: This should be a time.Time!
}
_With_ this fix, the following code is generated:
type ChatMessage struct {
ID string
Body string
CreatedAt time.Time
UpdatedAt time.Time // Fixed, now a time.Time, even for retroactively added columns
}1 parent 1851c0d commit 3c4ff4f
2 files changed
Lines changed: 40 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 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 | + | |
68 | 98 | | |
69 | 99 | | |
70 | 100 | | |
| |||
79 | 109 | | |
80 | 110 | | |
81 | 111 | | |
| 112 | + | |
82 | 113 | | |
83 | 114 | | |
84 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
75 | 79 | | |
76 | 80 | | |
77 | | - | |
| 81 | + | |
78 | 82 | | |
79 | 83 | | |
80 | 84 | | |
| |||
88 | 92 | | |
89 | 93 | | |
90 | 94 | | |
91 | | - | |
| 95 | + | |
92 | 96 | | |
93 | 97 | | |
94 | 98 | | |
| |||
826 | 830 | | |
827 | 831 | | |
828 | 832 | | |
829 | | - | |
| 833 | + | |
830 | 834 | | |
831 | 835 | | |
832 | 836 | | |
| |||
837 | 841 | | |
838 | 842 | | |
839 | 843 | | |
840 | | - | |
| 844 | + | |
841 | 845 | | |
842 | 846 | | |
843 | 847 | | |
| |||
0 commit comments