yangzhang75 commented on code in PR #7851:
URL: https://github.com/apache/texera/pull/7851#discussion_r3867565409


##########
sql/updates/41.sql:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+\c texera_db
+
+SET search_path TO texera_db;
+
+BEGIN;
+
+-- Version pinning: a public workflow follows the author's latest until they 
pin the version they
+-- have now, after which the public keeps seeing that frozen copy. is_public 
stays the on/off switch;
+-- published_content is the pin, NULL while following. Materialized rather 
than replayed from
+-- workflow_version, whose rows are reverse deltas that no fulltext index can 
cover.
+ALTER TABLE workflow
+    -- The version row holding the pinned copy. Its delta is the identity 
patch, so replaying it
+    -- returns exactly what is on public show; the revision panel marks that 
row, which is how the
+    -- author restores the public version into their editor.
+    ADD COLUMN IF NOT EXISTS published_version_id  INT,
+    ADD COLUMN IF NOT EXISTS published_content     TEXT,
+    ADD COLUMN IF NOT EXISTS published_name        VARCHAR(128),
+    ADD COLUMN IF NOT EXISTS published_description TEXT;
+
+-- No backfill. Every workflow that is public today has no pin, which is the 
following state, which is
+-- exactly what it does today: deploying this migration changes nothing anyone 
can see. Pinning is
+-- something an author opts into afterwards.
+
+-- A pin only means something while the workflow is public, so a private 
workflow must not carry one.
+-- Making that unrepresentable is cheaper than catching it: unpublishing 
clears the pin, and no other
+-- path writes these columns.
+DO
+$$
+    BEGIN
+        ALTER TABLE workflow DROP CONSTRAINT IF EXISTS 
workflow_published_consistent;
+        IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 
'workflow_pin_requires_public') THEN
+            ALTER TABLE workflow
+                ADD CONSTRAINT workflow_pin_requires_public
+                    CHECK (published_content IS NULL OR is_public);
+        END IF;

Review Comment:
   Fixed — drops and re-adds the constraint instead of checking for the name, 
same as texera_ddl.sql.



##########
sql/texera_ddl.sql:
##########
@@ -164,9 +164,28 @@ CREATE TABLE IF NOT EXISTS workflow
     content            TEXT NOT NULL,
     creation_time      TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
     last_modified_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
-    is_public          BOOLEAN NOT NULL DEFAULT false
+    is_public          BOOLEAN NOT NULL DEFAULT false,
+    -- is_public is the on/off switch; published_content is the pin. NULL 
means the public follows the
+    -- author's latest content, non-NULL is the frozen copy the public sees 
instead. Materialized
+    -- rather than reconstructed from workflow_version, whose rows are reverse 
deltas.
+    -- published_version_id names the version row holding that copy, which is 
what the revision panel
+    -- marks so the author can restore it.
+    published_version_id  INT,
+    published_content     TEXT,
+    published_name        VARCHAR(128),
+    published_description TEXT

Review Comment:
   Fixed — insertWorkflow now clears the four columns before the insert, with a 
test that posts them and checks they land NULL.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to