Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cascade or restrict on delete entities? #4672

Open
s8sato opened this issue May 30, 2024 · 5 comments
Open

cascade or restrict on delete entities? #4672

s8sato opened this issue May 30, 2024 · 5 comments
Labels
question Further information is requested

Comments

@s8sato
Copy link
Contributor

s8sato commented May 30, 2024

Currently, domains, accounts, and assets are cascaded on unregister due to nested structure, but for shallow objects #3921 we might choose either of the following unregister policies:

  1. autoremove orphans (ON DELETE CASCADE)
  • entity should have a set of references (IDs) of other entities
  1. do not unregister as long as referenced (ON DELETE RESTRICT)
  • entity should have a reference counter that indicates how many other entities are referencing it
@s8sato s8sato added the question Further information is requested label May 30, 2024
@s8sato
Copy link
Contributor Author

s8sato commented Jun 3, 2024

  • domains, accounts, and assets would keep cascading if that is implied in CanUnregisterDomain and CanUnregisterAccount
  • should an account be dominant for the triggers it has registered?

@s8sato s8sato changed the title cascade or protect on delete entities? cascade or restrict on delete entities? Jul 2, 2024
@s8sato
Copy link
Contributor Author

s8sato commented Jul 2, 2024

To consider entity relationships, I drew what if the storages under the world were tables of relational database:

erDiagram
    %% parent tables
    DOMAINS {
        _ id PK
        _ logo
        _ metadata
        _ admin FK
    }
    ACCOUNTS {
        _ id PK
        _ metadata
    }
    ASSETS {
        _ id PK
        _ total_quantity
        _ is_mintable
        _ logo
        _ metadata
        _ admin FK
    }
    %% child tables
    DOMAIN_ACCOUNTS {
        _ domain_id PK, FK
        _ account_id PK, FK
    }
    DOMAIN_ASSETS {
        _ domain_id PK, FK
        _ asset_id PK, FK
    }
    ASSET_ACCOUNTS_NUMERIC {
        _ asset_id PK, FK
        _ account_id PK, FK
        Numeric balance
    }
    ASSET_ACCOUNTS_STORE {
        _ asset_id PK, FK
        _ account_id PK, FK
        Metadata datastore
    }
    %% relationships
    DOMAINS ||--o{ DOMAIN_ACCOUNTS : has
    DOMAINS ||--o{ DOMAIN_ASSETS : has
    ACCOUNTS ||--o{ DOMAINS : administrates
    ACCOUNTS ||--o{ ASSETS : administrates
    ACCOUNTS ||--o{ DOMAIN_ACCOUNTS : has
    ACCOUNTS ||--o{ ASSET_ACCOUNTS_NUMERIC : has
    ACCOUNTS ||--o{ ASSET_ACCOUNTS_STORE : has
    ASSETS ||--o{ DOMAIN_ASSETS : serves
    ASSETS ||--o{ ASSET_ACCOUNTS_NUMERIC : serves
    ASSETS ||--o{ ASSET_ACCOUNTS_STORE : serves

Loading
erDiagram
    %% parent tables
    ACCOUNTS {
        _ id PK
        _ metadata
    }
    PERMISSIONS {
        _ id PK
    }
    ROLES {
        _ id PK
    }
    %% child tables
    ACCOUNT_PERMISSIONS {
        _ account_id PK, FK
        _ permission_id PK, FK
    }
    ACCOUNT_ROLES {
        _ account_id PK, FK
        _ role_id PK, FK
    }
    ROLE_PERMISSIONS {
        _ role_id PK, FK
        _ permission_id PK, FK
    }
    %% relationships
    ACCOUNTS ||--o{ ACCOUNT_PERMISSIONS : has
    ACCOUNTS ||--o{ ACCOUNT_ROLES : has
    PERMISSIONS ||--o{ ACCOUNT_PERMISSIONS : serves
    PERMISSIONS ||--o{ ROLE_PERMISSIONS : serves
    ROLES ||--o{ ROLE_PERMISSIONS : has
    ROLES ||--o{ ACCOUNT_ROLES : serves

Loading

where:

  • if table P has table C, entity c in C that references p is also deleted when entity p in P is deleted (CASCADE)
  • if table P serves table C, entity p in P cannot be deleted as long as any entity c in C references p (RESTRICT)
  • P serves C when P administrates C

@Erigara
Copy link
Contributor

Erigara commented Jul 2, 2024

Interesting, when you visualized it this way i noticed that either removal of account or domain can have cascade a lot.

Like:

  1. removal of domain owner would delete it's domain
  2. which in turn delete every account in this domain
  3. if any account in this domain was domain owner it trigger domain removal
  4. ...
  5. Until domain is empty or every account in the domain is not owner of some other domain

@s8sato
Copy link
Contributor Author

s8sato commented Jul 2, 2024

As long as ACCOUNTS serves DOMAINS, as suggested, the removal of the domain owner would be restricted. But yeah, this is exactly the kind of discussion I wanted to have

@s8sato
Copy link
Contributor Author

s8sato commented Jul 5, 2024

updates:

erDiagram
    %% parent tables
    DOMAINS {
        _ id PK
        _ logo
        _ metadata
        _ admin FK
    }
    ACCOUNTS {
        _ id PK
        _ metadata
        _ domain_id FK
    }
    FASSETS {
        %% fungible assets
        _ id PK
        Numeric total_quantity
        _ is_mintable
        _ logo
        _ metadata
        _ admin FK
        _ domain_id FK
    }
    NFASSETS {
        %% non-fungible assets
        _ id PK
        Metadata datastore
        _ owner FK
        _ domain_id FK
    }
    %% child tables
    FASSET_ACCOUNTS {
        _ asset_id PK, FK
        _ account_id PK, FK
        Numeric balance
    }
    %% relationships
    DOMAINS ||--o{ ACCOUNTS : has
    DOMAINS ||--o{ FASSETS : has
    DOMAINS ||--o{ NFASSETS : has
    ACCOUNTS ||--o{ DOMAINS : administrates
    ACCOUNTS ||--o{ FASSETS : administrates
    ACCOUNTS ||--o{ FASSET_ACCOUNTS : has
    ACCOUNTS ||--o{ NFASSETS : has
    FASSETS ||--o{ FASSET_ACCOUNTS : serves

Loading

where:

  • FASSET is an abbreviation for FUNGIBLE ASSET
  • NFASSET is an abbreviation for NON FUNGIBLE ASSET
  • some additional views would be desired for reference e.g. DOMAIN_ACCOUNTS, DOMAIN_ASSETS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants