Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema Migration annotations #1162

Open
EnoF opened this issue Mar 14, 2023 · 1 comment
Open

Schema Migration annotations #1162

EnoF opened this issue Mar 14, 2023 · 1 comment

Comments

@EnoF
Copy link

EnoF commented Mar 14, 2023

Currently migrating deployed schema's is very cumbersome to maintain. You could
attempt to migrate schema's like:

(defschema old-schema
  old: string)

(defschema new-schema
  new: string)

(defun get-row(id: string)
  (try
    (with-read table id
      { "new":= new }
      { "new": new })
    (with-read table id
      { "old":= old }
      (update table id { "new": old })
      { "new": old })))

Note, not sure if this code works.

This would maybe work for moving schema attributes, but what about adding a new column?
Or changing the type of an existing column?

To assist in such migration I'd like to propose the following schema annotations:

(defschema new-schema
  @moved(new)
  old: string
  new: string
  @convert(str-to-int)
  @convert(custom-func-to-convert)
  type-changed: integer ; assuming the old schema was a string
  @default("default value if not present")
  new-column: string)
@EnoF
Copy link
Author

EnoF commented Mar 15, 2023

After some further testing you could do something like this:

(try 
  (with-read 
    table
    "id" 
    { 'foobar  := foobar }
    foobar)
  (with-read 
    table
    "id" 
    { 'foo:= foo
    , 'bar:= bar }
    (update table "id" { 'foobar: { 'foo: foo, 'bar: bar }})
    { 'foo: foo
    , 'bar: bar  }))

Note that every new insert will need to fill the old attributes foo, bar with empty valid values and this won't support type changes of a column.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant