dosubot[bot] commented on issue #29288:
URL: https://github.com/apache/superset/issues/29288#issuecomment-2175555345

   <!-- Greeting -->
   Hey there, @fgvieira! I'm here to assist you with any bugs, questions, or 
contributions you might have for the repository. Let me know how I can help you!
   
   <!-- Answer -->
   To resolve the warnings encountered when running `superset db upgrade` after 
installing Superset using conda, you can follow the steps outlined in the 
migration script provided. The script ensures that any duplicates are removed 
and a unique constraint is created on the `tagged_object` table.
   
   Here is the relevant code from the migration script:
   
   ```python
   def upgrade():
       bind = op.get_bind()  # Get the database connection bind
   
       # Reflect the current database state to get existing tables
       metadata.reflect(bind=bind)
   
       # Delete duplicates if any
       min_id_subquery = (
           select(
               [
                   func.min(tagged_object_table.c.id).label("min_id"),
                   tagged_object_table.c.tag_id,
                   tagged_object_table.c.object_id,
                   tagged_object_table.c.object_type,
               ]
           )
           .group_by(
               tagged_object_table.c.tag_id,
               tagged_object_table.c.object_id,
               tagged_object_table.c.object_type,
           )
           .alias("min_ids")
       )
   
       delete_query = tagged_object_table.delete().where(
           tagged_object_table.c.id.notin_(select([min_id_subquery.c.min_id]))
       )
   
       bind.execute(delete_query)
   
       # Create unique constraint
       utils.create_unique_constraint(op, index_id, table_name, uix_columns)
   ```
   
   This script performs the following actions:
   1. Reflects the current database state to get existing tables.
   2. Deletes any duplicate entries in the `tagged_object` table.
   3. Creates a unique constraint on the `tagged_object` table to prevent 
future duplicates.
   
   Ensure that you have the `migration_utils` module available and properly 
configured, as it is used to create and drop the unique constraint.
   
   Additionally, after running the migration script, you should follow the 
standard procedure for upgrading Superset's metadata database:
   
   ```bash
   superset db upgrade
   superset init
   ```
   
   While upgrading Superset should not delete your charts and dashboards, it is 
recommended to backup your metadata database before upgrading. For production 
environments, consider upgrading in a staging environment first and then 
upgrading production during off-peak hours.
   
   Refer to the `UPDATING.md` file for any potential downtime or breaking 
changes that might affect your deployment. For example, adding an index to 
`query.sql_editor_id` or updating database columns to use the `MediumText` type 
might require some downtime on large deployments. Always review the latest 
updates and changes to ensure a smooth upgrade process 
<sup>[[1]](https://github.com/apache/superset/blob/master/superset/migrations/versions/2024-01-17_13-09_96164e3017c6_tagged_object_unique_constraint.py)</sup><sup>[[2]](https://github.com/apache/superset/blob/master/docs/docs/installation/upgrading-superset.mdx)</sup><sup>[[3]](https://github.com/apache/superset/blob/master/UPDATING.md)</sup>.
   
   
   <!-- Dosu Comment Footer -->
   *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
   


-- 
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]

Reply via email to