You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2022/04/01 14:05:48 UTC

[superset] 01/02: create table for sl_dataset_users table

This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch add-owners-new-dataset
in repository https://gitbox.apache.org/repos/asf/superset.git

commit a0df608e5d98dcf482fd9375cdd207ceace0fd3e
Author: hughhhh <hu...@gmail.com>
AuthorDate: Thu Mar 31 22:26:48 2022 -0400

    create table for sl_dataset_users table
---
 superset/datasets/models.py                        | 12 +++++
 .../89f17d951737_add_owners_dataset_model.py       | 51 ++++++++++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/superset/datasets/models.py b/superset/datasets/models.py
index 56a6fbf..bcd8add 100644
--- a/superset/datasets/models.py
+++ b/superset/datasets/models.py
@@ -30,6 +30,7 @@ import sqlalchemy as sa
 from flask_appbuilder import Model
 from sqlalchemy.orm import relationship
 
+from superset import security_manager
 from superset.columns.models import Column
 from superset.models.helpers import (
     AuditMixinNullable,
@@ -52,6 +53,13 @@ table_association_table = sa.Table(
     sa.Column("table_id", sa.ForeignKey("sl_tables.id")),
 )
 
+dataset_user = sa.Table(
+    "sl_dataset_users",
+    Model.metadata,
+    sa.Column("user_id", sa.ForeignKey("ab_user.id")),
+    sa.Column("dataset_id", sa.ForeignKey("sl_datasets.id")),
+)
+
 
 class Dataset(Model, AuditMixinNullable, ExtraJSONMixin, ImportExportMixin):
     """
@@ -90,3 +98,7 @@ class Dataset(Model, AuditMixinNullable, ExtraJSONMixin, ImportExportMixin):
     # Column is managed externally and should be read-only inside Superset
     is_managed_externally = sa.Column(sa.Boolean, nullable=False, default=False)
     external_url = sa.Column(sa.Text, nullable=True)
+
+    owners = relationship(
+        security_manager.user_model, secondary=dataset_user, backref="sl_datasets"
+    )
diff --git a/superset/migrations/versions/89f17d951737_add_owners_dataset_model.py b/superset/migrations/versions/89f17d951737_add_owners_dataset_model.py
new file mode 100644
index 0000000..5b83609
--- /dev/null
+++ b/superset/migrations/versions/89f17d951737_add_owners_dataset_model.py
@@ -0,0 +1,51 @@
+# 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.
+"""add_owners_dataset_model
+
+Revision ID: 89f17d951737
+Revises: 2ed890b36b94
+Create Date: 2022-03-31 22:22:43.831122
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "89f17d951737"
+down_revision = "2ed890b36b94"
+
+import sqlalchemy as sa
+from alembic import op
+from sqlalchemy.dialects import postgresql
+
+
+def upgrade():
+    op.create_table(
+        "sl_dataset_users",
+        sa.Column("user_id", sa.Integer(), nullable=True),
+        sa.Column("dataset_id", sa.Integer(), nullable=True),
+        sa.ForeignKeyConstraint(
+            ["dataset_id"],
+            ["sl_datasets.id"],
+        ),
+        sa.ForeignKeyConstraint(
+            ["user_id"],
+            ["ab_user.id"],
+        ),
+    )
+
+
+def downgrade():
+    op.drop_table("sl_dataset_users")