Saturday, December 3, 2022

Model with shared table among schemas

Hi all.
I have a simple Django app deployed as **two separated instances** on same server. These instances need to be separeted (same DB, different schemas) and they don't need to interect each other except for a single table (`bm_catalog`, coupled to its corresponding `class Catalog` - which estends `models.Model`). The model `Catalog` is used by both app's instances to read common data.
I decided to store this shared table in the **public** schema:

```
class Catalog(models.Model):
    description = models.CharField(max_length=255)
    link = models.CharField(max_length=255, null=True)

    class Meta:
        db_table = '"public"."bm_catalog"'
```

`bm_catalog` is owned by user 'postgres' and granted to be accessed by other schemas.
After some adjustments it finally works but I have 2 questions:

1. When i run `manage.py migrate` on the first instance it works, but when I run same command on the second instance I get an error saying the table (obviously) already exists. Nontheless (sooner or later) I need to migrate both instances...

2. Everytime I will have to alter the class Catalog I will run in the same previous issue.

Do you have any advice? (or an alternative approach to suggest?)
I would avoid to use multi-tenant packages, if possible.

Thanks in advance,
Paolo

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fa337071-4563-4a76-ac5b-ae43daeb67e4n%40googlegroups.com.

No comments:

Post a Comment