Gen migrate add varchar(N), blob(N) default, collates#279
Conversation
b14a9c0 to
096f4c3
Compare
|
|
||
| let current_lexbuf : Lexing.lexbuf option ref = ref None | ||
|
|
||
| let with_lexbuf lexbuf f = | ||
| let saved = !current_lexbuf in | ||
| current_lexbuf := Some lexbuf; | ||
| Fun.protect f ~finally:(fun () -> current_lexbuf := saved) | ||
|
|
||
| let extract_source (start_, end_) = | ||
| Option.map (fun lexbuf -> | ||
| let offset = start_ - lexbuf.Lexing.lex_abs_pos in | ||
| String.trim (Bytes.sub_string lexbuf.Lexing.lex_buffer offset (end_ - start_)) | ||
| ) !current_lexbuf |
There was a problem hiding this comment.
The issue even isn't that the default isn't unified. It's that it's any expression. This means we need expr->string, which fully restores the expression as an SQL string. And that requires a separate PR. So, we temporarily capture it as a string. Hence the hack in the parser state.
| let pos = ($startofs(def), $endofs(def)) in | ||
| Some (Alter_action_attr.Default { | ||
| expr = make_located ~value:def ~pos; | ||
| sql = Parser_state.extract_source pos; | ||
| }) | ||
| } |
There was a problem hiding this comment.
A temporary solution is to keep the DEFAULT expression as-is until its type is unified with the column type.
7e385e0 to
02836d0
Compare
305476e to
89149e5
Compare
|
i think it is ok to keep column attributes as text for the purpose of migration gen (use structured repr for other uses like typechecking etc), because it could be some custom database specific attributes that we don't parse and it seems better to do something reasonable (pass them verbatim) than just fail |
89149e5 to
7cb2a71
Compare
default is only as sql str
7cb2a71 to
3ff5779
Compare
Description
This PR adds proper support for VARCHAR(N), CHAR(N), VARCHAR2, BLOB(N), VARBINARY(N), TINYTEXT/MEDIUMTEXT/LONGTEXT (and their blob variants), and DECIMAL(p) in gen_migrations.
Previously these types were normalized into plain TEXT/BLOB/DECIMAL, so inverse migrations lost the original type flavor and length information.
Inverse migrations now also preserve COLLATE and DEFAULT clauses when reconstructing columns from the stored schema. Before this change, those attributes were silently dropped.
For now, DEFAULT values are stored as raw SQL fragments and replayed verbatim in inverse migrations. This is temporary. Once DEFAULT expressions are typechecked against the column type, they can be represented as structured values instead of opaque SQL text.