-
Notifications
You must be signed in to change notification settings - Fork 140
feat(python-notebook-migration): add database tables for Notebook Migration tool #5055
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
base: main
Are you sure you want to change the base?
Changes from all commits
e60310e
c8fa486
986bd38
9c63915
6deb604
4387ad0
914f6b5
f4e019a
bc8381c
89015d3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,8 @@ DROP TABLE IF EXISTS dataset_user_likes CASCADE; | |
| DROP TABLE IF EXISTS dataset_view_count CASCADE; | ||
| DROP TABLE IF EXISTS site_settings CASCADE; | ||
| DROP TABLE IF EXISTS computing_unit_user_access CASCADE; | ||
| DROP TABLE IF EXISTS notebook CASCADE; | ||
| DROP TABLE IF EXISTS workflow_notebook_mapping CASCADE; | ||
|
|
||
| -- ============================================ | ||
| -- 4. Create PostgreSQL enum types | ||
|
|
@@ -435,6 +437,28 @@ CREATE TABLE IF NOT EXISTS computing_unit_user_access | |
| FOREIGN KEY (uid) REFERENCES "user"(uid) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| -- notebook table | ||
| CREATE TABLE IF NOT EXISTS notebook | ||
| ( | ||
| nid SERIAL NOT NULL PRIMARY KEY, | ||
| wid INT NOT NULL, | ||
| notebook JSONB NOT NULL, | ||
| FOREIGN KEY (wid) REFERENCES workflow(wid) ON DELETE CASCADE | ||
| ); | ||
|
Comment on lines
+441
to
+447
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main read pattern for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that indexing |
||
|
|
||
| -- workflow_notebook_mapping table | ||
| CREATE TABLE IF NOT EXISTS workflow_notebook_mapping | ||
| ( | ||
| wid INT NOT NULL, | ||
| vid INT NOT NULL, | ||
| nid INT NOT NULL, | ||
| mapping JSONB NOT NULL, | ||
| PRIMARY KEY (wid, vid, nid), | ||
| FOREIGN KEY (wid) REFERENCES workflow(wid) ON DELETE CASCADE, | ||
| FOREIGN KEY (vid) REFERENCES workflow_version(vid) ON DELETE CASCADE, | ||
| FOREIGN KEY (nid) REFERENCES notebook(nid) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| -- START Fulltext search index creation (DO NOT EDIT THIS LINE) | ||
| CREATE EXTENSION IF NOT EXISTS pgroonga; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| -- ============================================ | ||
| -- 1. Connect to the texera_db database | ||
| -- ============================================ | ||
| SET search_path TO texera_db; | ||
|
|
||
| -- ============================================ | ||
| -- 2. Create the tables to store notebook and mapping | ||
| -- ============================================ | ||
|
|
||
| BEGIN; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS notebook ( | ||
| nid SERIAL NOT NULL PRIMARY KEY, | ||
| wid INT NOT NULL, | ||
| notebook JSONB NOT NULL, | ||
| FOREIGN KEY (wid) REFERENCES workflow(wid) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS workflow_notebook_mapping ( | ||
| wid INT NOT NULL, | ||
| vid INT NOT NULL, | ||
| nid INT NOT NULL, | ||
| mapping JSONB NOT NULL, | ||
| PRIMARY KEY (wid, vid, nid), | ||
| FOREIGN KEY (wid) REFERENCES workflow(wid) ON DELETE CASCADE, | ||
| FOREIGN KEY (vid) REFERENCES workflow_version(vid) ON DELETE CASCADE, | ||
| FOREIGN KEY (nid) REFERENCES notebook(nid) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| COMMIT; |
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.
Cardinality question: nothing in the schema prevents inserting two
notebookrows for the samewid, but the parent issue (#4301, demo #5 "when the user reopens a workflow that was generated from a notebook, it will also reopen the notebook") reads like a 1:1 relationship. If a workflow is supposed to have at most one notebook, would aUNIQUE (wid)onnotebook(or makingwidthe PK in place ofnid) be safer than relying on application code to enforce it?Uh oh!
There was an error while loading. Please reload this page.
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.
In the current prototype implementation, you are correct in that a workflow will only ever have one notebook (a 1:1 relationship). However, the reason the schema is designed this way is because we wanted to allow future work to make the notebook editable and savable, which would create the situation where multiple notebooks (or versions of the same notebook) are linked to the same workflow. This is why we didn't make
widUNIQUE here.Alternatively, another option is that we can make
widUNIQUE in this PR, and when the aforementioned future work is done then we can make the schema change to allow multiple notebooks for a workflow. What do you think?