betodealmeida commented on a change in pull request #8060: SIP-23: Persist SQL 
Lab state in the backend
URL: 
https://github.com/apache/incubator-superset/pull/8060#discussion_r317208874
 
 

 ##########
 File path: superset/models/sql_lab.py
 ##########
 @@ -188,6 +189,80 @@ def url(self):
         return "/superset/sqllab?savedQueryId={0}".format(self.id)
 
 
+class TabState(Model, AuditMixinNullable, ExtraJSONMixin):
+
+    __tablename__ = "tab_state"
+
+    # basic info
+    id = Column(Integer, primary_key=True)
+    user_id = Column(Integer, ForeignKey("ab_user.id"))
+    label = Column(String(256))
+    active = Column(Boolean, default=False)
+
+    # selected DB and schema
+    database_id = Column(Integer, ForeignKey("dbs.id"))
+    database = relationship("Database", foreign_keys=[database_id])
+    schema = Column(String(256))
+
+    # tables that are open in the schema browser and their data previews
+    table_schemas = relationship(
+        "TableSchema", cascade="all,delete", backref="tab_state"
+    )
+
+    # the query in the textarea, and results (if any)
+    query_id = Column(Integer, ForeignKey("query.id"))
+    query = relationship("Query")
+    query_limit = Column(Integer)
+
+    # other properties
+    autorun = Column(Boolean, default=False)
+    template_params = Column(Text)
+
+    def to_dict(self):
+        return {
+            "id": self.id,
+            "user_id": self.user_id,
+            "label": self.label,
+            "active": self.active,
+            "database_id": self.database_id,
+            "schema": self.schema,
+            "table_schemas": [ts.to_dict() for ts in self.table_schemas],
+            "query": self.query.to_dict(),
+            "query_limit": self.query_limit,
+            "autorun": self.autorun,
+            "template_params": self.template_params,
+        }
+
+
+class TableSchema(Model, AuditMixinNullable, ExtraJSONMixin):
+
+    __tablename__ = "table_schema"
+
+    id = Column(Integer, primary_key=True)
+    tab_state_id = Column(Integer, ForeignKey("tab_state.id"))
+
+    database_id = Column(Integer, ForeignKey("dbs.id"), nullable=False)
+    database = relationship("Database", foreign_keys=[database_id])
+    schema = Column(String(256))
+    table = Column(String(256))
+
+    # JSON describing the schema, partitions, latest partition, etc.
+    results = Column(Text)
 
 Review comment:
   Good point. This is only for metadata, the results are stored in the results 
backend (if configured), and retrieved when the tab loads. I'll rename it.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to