villebro commented on code in PR #36368: URL: https://github.com/apache/superset/pull/36368#discussion_r2748211860
########## superset/migrations/versions/2025_12_18_0220_create_tasks_table.py: ########## @@ -0,0 +1,217 @@ +# 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. +"""Create tasks and task_subscriber tables for Global Task Framework (GTF) + +Revision ID: 4b2a8c9d3e1f +Revises: 9787190b3d89 +Create Date: 2025-12-18 02:20:00.000000 + +""" + +from sqlalchemy import ( + Column, + DateTime, + Integer, + String, + Text, + UniqueConstraint, +) + +from superset.migrations.shared.utils import ( + create_fks_for_table, + create_index, + create_table, + drop_fks_for_table, + drop_index, + drop_table, +) + +# revision identifiers, used by Alembic. +revision = "4b2a8c9d3e1f" +down_revision = "9787190b3d89" + +TASKS_TABLE = "tasks" +TASK_SUBSCRIBERS_TABLE = "task_subscribers" + + +def upgrade(): + """ + Create tasks and task_subscribers tables for the Global Task Framework (GTF). + + This migration creates: + 1. tasks table - unified tracking for all long running tasks + 2. task_subscribers table - multi-user task subscriptions for shared tasks + + The scope feature allows tasks to be: + - private: user-specific (default) + - shared: multi-user collaborative tasks + - system: admin-only background tasks + """ + # Create tasks table + create_table( + TASKS_TABLE, + Column("id", Integer, primary_key=True), + Column("uuid", String(36), nullable=False, unique=True), + Column("task_key", String(256), nullable=False), # For deduplication + Column("task_type", String(100), nullable=False), # e.g., 'sql_execution' + Column("task_name", String(256), nullable=True), # Human readable name + Column( + "scope", String(20), nullable=False, server_default="private" + ), # private/shared/system + Column("status", String(50), nullable=False), # PENDING, IN_PROGRESS, etc. + Column("dedup_key", String(512), nullable=False), # Computed deduplication key + # AuditMixinNullable columns + Column("created_on", DateTime, nullable=True), + Column("changed_on", DateTime, nullable=True), + Column("created_by_fk", Integer, nullable=True), + Column("changed_by_fk", Integer, nullable=True), + # Task-specific columns + Column("started_at", DateTime, nullable=True), + Column("ended_at", DateTime, nullable=True), + Column("user_id", Integer, nullable=True), # User context for execution + Column("payload", Text, nullable=True), # JSON serialized task-specific data + Column("properties", Text, nullable=True), # JSON serialized properties + ) + + # Create indexes for optimal query performance + create_index(TASKS_TABLE, "idx_tasks_dedup_key", ["dedup_key"], unique=True) Review Comment: scope is included in the dedup key -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
