-
Notifications
You must be signed in to change notification settings - Fork 46
feat: allow SQL files to be imported #89
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
Conversation
fix: include SQL files during testing
e5af999 to
dd0d370
Compare
| // Install default necessary `tmp_` tables for various features here. | ||
| const cacheStatement = ` | ||
| CREATE TABLE IF NOT EXISTS tmp_cache ( | ||
| "id" INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| "timestamp" REAL NOT NULL, | ||
| "ttl" INTEGER NOT NULL, | ||
| "query" TEXT UNIQUE NOT NULL, | ||
| "results" TEXT | ||
| );` | ||
|
|
||
| const allowlistStatement = ` | ||
| CREATE TABLE IF NOT EXISTS tmp_allowlist_queries ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| sql_statement TEXT NOT NULL, | ||
| source TEXT DEFAULT 'external' | ||
| )` | ||
| const allowlistRejectedStatement = ` | ||
| CREATE TABLE IF NOT EXISTS tmp_allowlist_rejections ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| sql_statement TEXT NOT NULL, | ||
| source TEXT DEFAULT 'external', | ||
| created_at TEXT DEFAULT (datetime('now')) | ||
| )` | ||
|
|
||
| const rlsStatement = ` | ||
| CREATE TABLE IF NOT EXISTS tmp_rls_policies ( | ||
| "id" INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| "actions" TEXT NOT NULL CHECK(actions IN ('SELECT', 'UPDATE', 'INSERT', 'DELETE')), | ||
| "schema" TEXT, | ||
| "table" TEXT NOT NULL, | ||
| "column" TEXT NOT NULL, | ||
| "value" TEXT NOT NULL, | ||
| "value_type" TEXT NOT NULL DEFAULT 'string', | ||
| "operator" TEXT DEFAULT '=' | ||
| )` | ||
|
|
||
| this.executeQuery({ sql: cacheStatement }) | ||
| this.executeQuery({ sql: allowlistStatement }) | ||
| this.executeQuery({ sql: allowlistRejectedStatement }) | ||
| this.executeQuery({ sql: rlsStatement }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, all of these will soon be moving away from being directly built in (when possible) to being their own plugins as well as to not potentially pollute new instances with tables or features that don't make sense for a users use case.
Brayden
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do very much like the idea of enabling plugins themselves to include/import .sql files into their project, that part is great.
My fear would be including two default files (builtin.sql and user.sql) like this instead of adopting a more standardized migrations implementation – ref: https://github.com/lambrospetrou/durable-utils?tab=readme-ov-file#sqlite-schema-migrations
Current suggestion would be to include the work in this PR that allows .sql files to be included but at the moment not commit to adopting a two file default for SQL statements to instantiate a DO until we take a deeper dive into what a proper migrations setup could do for us.
Are you okay with that @jeroenptrs?
|
@Brayden sounds good! this stemmed from not seeing a good encapsulated way to bootstrap a database, but moving to migrations (potentially as a plugin) makes sense. Will adapt the PR in a bit! |
dd0d370 to
3f0b454
Compare
|
@Brayden since the scope of the PR changed I also renamed it, let me know if these changes make sense! |
Brayden
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice work 🚀
Purpose
Sparked by the conversation on #50, I wanted to provide a way to easily provide statements through SQL files.
Tasks
rules, ref here)Verify
Before
No sql file support
After
Anything I write in this file gets reflected when the DO initializes 🙂