trailbaseio / trailbase

A blazingly fast, single-file, open-source application server with type-safe APIs, Auth, and Admin UI built on Rust+SQLite.
https://trailbase.io
Open Software License 3.0
152 stars 4 forks source link

Invalid CREATE TABLE and CREATE INDEX SQL #5

Closed ignatz closed 1 week ago

ignatz commented 1 week ago

Reported by a user on reddit (https://www.reddit.com/r/selfhosted/comments/1grf3m8/comment/lxb2m0z/?context=3):


    Once I can see the foreign key, it cannot create the link (due to syntax error), and looking at the generated SQL it isn't valid:

     CREATE TABLE todos2 (
       id BLOB PRIMARY KEY CHECK(is_uuid_v7(id)) DEFAULT (uuid_v7()) NOT NULL,
       user BLOB DEFAULT '' FOREIGN KEY(user) REFERENCES _user(id),
       name TEXT NOT NULL
     ) STRICT;

but it should be the following (FOREIGN KEY syntax isn't valid in SQLIte I believe) :

CREATE TABLE todos2 (
  id BLOB PRIMARY KEY DEFAULT (uuid_v7()) CHECK (is_uuid_v7(id)) NOT NULL,
  user BLOB DEFAULT '' REFERENCES _user(id),
  name TEXT NOT NULL
) STRICT;

    Similarly, creating an index (just including the id column) gives an error related to JSON and the missing field "if_not_exists".