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

Delete Relational Data Automatically Upon Deleting Main Data #13773

Closed
3 tasks done
ChristopherGabba opened this issue Aug 30, 2024 · 1 comment
Closed
3 tasks done

Delete Relational Data Automatically Upon Deleting Main Data #13773

ChristopherGabba opened this issue Aug 30, 2024 · 1 comment
Labels
pending-triage Issue is pending triage

Comments

@ChristopherGabba
Copy link

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

GraphQL API

Amplify Version

v6

Amplify Categories

api

Backend

None

Environment information

# Put output below this line
  System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M2 Pro
    Memory: 76.84 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.7.0 - /opt/homebrew/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.8.2 - /opt/homebrew/bin/npm
    Watchman: 2024.08.12.00 - /opt/homebrew/bin/watchman
  Browsers:
    Safari: 17.5
  npmPackages:
    %name%:  0.1.0 
    @aws-amplify/backend: 1.2.0 => 1.2.0 
    @aws-amplify/backend-cli: 1.2.5 => 1.2.5 
    @aws-amplify/react-native: 1.1.4 => 1.1.4 
    @aws-amplify/ui-react-native: 2.2.5 => 2.2.5 
    @aws-appsync/utils: ^1.7.0 => 1.9.0 
    @babel/core: ^7.20.0 => 7.25.2 
    @babel/plugin-proposal-export-namespace-from: ^7.18.9 => 7.18.9 
    @babel/plugin-proposal-optional-chaining: ^7.0.0 => 7.21.0 
    @babel/plugin-transform-arrow-functions: ^7.0.0 => 7.24.7 
    @babel/plugin-transform-nullish-coalescing-operator: ^7.0.0 => 7.24.7 
    @babel/plugin-transform-shorthand-properties: ^7.0.0 => 7.24.7 
    @babel/plugin-transform-template-literals: ^7.0.0 => 7.24.7 
    @babel/preset-env: ^7.20.0 => 7.25.4 
    @babel/runtime: ^7.20.0 => 7.25.4 
    @config-plugins/ffmpeg-kit-react-native: ^8.0.0 => 8.0.0 
    @expo-google-fonts/m-plus-1p: ^0.2.3 => 0.2.3 
    @expo-google-fonts/montserrat: ^0.2.3 => 0.2.3 
    @expo/config-plugins: ~8.0.0 => 8.0.8 
    @expo/metro-runtime: ~3.2.3 => 3.2.3 
    @gorhom/bottom-sheet: ^4.6.1 => 4.6.4 
    @react-native-async-storage/async-storage: 1.23.1 => 1.23.1 (1.24.0)
    @react-native-community/netinfo: 11.3.1 => 11.3.1 
    @react-native-menu/menu: ^1.1.0 => 1.1.2 
    @react-navigation/bottom-tabs: 6.6.1 => 6.6.1 
    @react-navigation/native: 6.1.18 => 6.1.18 
    @react-navigation/native-stack: 6.11.0 => 6.11.0 
    @sentry/react-native: ~5.22.0 => 5.22.3 
    @shopify/flash-list: 1.6.4 => 1.6.4 
    @types/i18n-js: 3.8.2 => 3.8.2 
    @types/jest: ^29.2.1 => 29.5.12 
    @types/lodash.filter: ^4.6.9 => 4.6.9 
    @types/node: ^22.5.0 => 22.5.1 (20.16.2, 18.19.47)
    @types/react: ~18.2.14 => 18.2.79 (18.3.4)
    @types/react-test-renderer: ^18.0.0 => 18.3.0 
    @typescript-eslint/eslint-plugin: ^5.59.0 => 5.62.0 
    @typescript-eslint/parser: ^5.59.0 => 5.62.0 
    ContextAPIMixpanel:  0.0.1 
    HelloWorld:  0.0.1 
    MixpanelDemo:  0.0.1 
    SimpleMixpanel:  0.0.1 
    apisauce: 3.0.1 => 3.0.1 
    aws-amplify: 6.5.3 => 6.5.3 
    aws-amplify/adapter-core:  undefined ()
    aws-amplify/analytics:  undefined ()
    aws-amplify/analytics/kinesis:  undefined ()
    aws-amplify/analytics/kinesis-firehose:  undefined ()
    aws-amplify/analytics/personalize:  undefined ()
    aws-amplify/analytics/pinpoint:  undefined ()
    aws-amplify/api:  undefined ()
    aws-amplify/api/server:  undefined ()
    aws-amplify/auth:  undefined ()
    aws-amplify/auth/cognito:  undefined ()
    aws-amplify/auth/cognito/server:  undefined ()
    aws-amplify/auth/enable-oauth-listener:  undefined ()
    aws-amplify/auth/server:  undefined ()
    aws-amplify/data:  undefined ()
    aws-amplify/data/server:  undefined ()
    aws-amplify/datastore:  undefined ()
    aws-amplify/in-app-messaging:  undefined ()
    aws-amplify/in-app-messaging/pinpoint:  undefined ()
    aws-amplify/push-notifications:  undefined ()
    aws-amplify/push-notifications/pinpoint:  undefined ()
    aws-amplify/storage:  undefined ()
    aws-amplify/storage/s3:  undefined ()
    aws-amplify/storage/s3/server:  undefined ()
    aws-amplify/storage/server:  undefined ()
    aws-amplify/utils:  undefined ()
    aws-cdk: ^2.154.1 => 2.154.1 
    aws-cdk-lib: ^2.154.1 => 2.154.1 
    babel-jest: ^29.2.1 => 29.7.0 
    cheerio: 1.0.0-rc.12 => 1.0.0-rc.12 
    constructs: ^10.3.0 => 10.3.0 
    date-fns: ^2.30.0 => 2.30.0 
    esbuild: ^0.21.1 => 0.21.5 (0.23.1)
    eslint: 8.17.0 => 8.17.0 
    eslint-config-prettier: 8.5.0 => 8.5.0 
    eslint-config-standard: 17.0.0 => 17.0.0 
    eslint-plugin-import: 2.26.0 => 2.26.0 
    eslint-plugin-n: ^15.0.0 => 15.7.0 
    eslint-plugin-promise: 6.0.0 => 6.0.0 
    eslint-plugin-react: 7.30.0 => 7.30.0 
    eslint-plugin-react-native: 4.0.0 => 4.0.0 
    eslint-plugin-reactotron: ^0.1.2 => 0.1.5 
    ex: ^0.1.4 => 0.1.4 
    expo: ~51.0.28 => 51.0.31 
    expo-application: ~5.9.1 => 5.9.1 
    expo-av: ~14.0.7 => 14.0.7 
    expo-blur: ~13.0.2 => 13.0.2 
    expo-build-properties: ~0.12.5 => 0.12.5 
    expo-clipboard: ~6.0.3 => 6.0.3 
    expo-constants: ~16.0.2 => 16.0.2 
    expo-contacts: ~13.0.5 => 13.0.5 
    expo-dev-client: ~4.0.24 => 4.0.25 
    expo-device: ~6.0.2 => 6.0.2 
    expo-file-system: ~17.0.1 => 17.0.1 
    expo-font: ~12.0.9 => 12.0.9 
    expo-haptics: ~13.0.1 => 13.0.1 
    expo-image: ~1.12.14 => 1.12.15 
    expo-image-picker: ~15.0.7 => 15.0.7 
    expo-linear-gradient: ~13.0.2 => 13.0.2 
    expo-linking: ~6.3.1 => 6.3.1 
    expo-localization: ~15.0.3 => 15.0.3 
    expo-notifications: ~0.28.16 => 0.28.16 
    expo-secure-store: ~13.0.2 => 13.0.2 
    expo-share-intent: ^2.0.0 => 2.3.0 
    expo-splash-screen: ~0.27.5 => 0.27.5 
    expo-status-bar: ~1.12.1 => 1.12.1 
    expo-store-review: ~7.0.2 => 7.0.2 
    expo-updates: ~0.25.23 => 0.25.24 
    expo-video-thumbnails: ~8.0.0 => 8.0.0 
    ffmpeg-kit-react-native: ^6.0.2 => 6.0.2 
    i18n-js: 3.9.2 => 3.9.2 
    jest: ^29.2.1 => 29.7.0 
    jest-expo: ~51.0.4 => 51.0.4 
    libphonenumber-js: ^1.11.1 => 1.11.7 (1.9.47)
    libphonenumber-js-core:  undefined (1.0.0)
    libphonenumber-js-max:  undefined (1.0.0)
    libphonenumber-js-min:  undefined (1.0.0)
    libphonenumber-js-mobile:  undefined (1.0.0)
    libphonenumber-js/build:  undefined ()
    libphonenumber-js/core:  undefined ()
    libphonenumber-js/max:  undefined ()
    libphonenumber-js/max/metadata:  undefined ()
    libphonenumber-js/min:  undefined ()
    libphonenumber-js/min/metadata:  undefined ()
    libphonenumber-js/mobile:  undefined ()
    libphonenumber-js/mobile/examples:  undefined ()
    libphonenumber-js/mobile/metadata:  undefined ()
    lodash: ^4.17.21 => 4.17.21 
    lodash.filter: ^4.6.0 => 4.6.0 
    lottie-react-native: 6.7.0 => 6.7.0 
    mixpanel-react-native: ^3.0.2 => 3.0.5 
    mixpanelexpo:  1.0.0 
    mobx: 6.10.2 => 6.10.2 
    mobx-react-lite: 4.0.5 => 4.0.5 
    mobx-state-tree: 6.0.1 => 6.0.1 
    patch-package: 6.4.7 => 6.4.7 
    postinstall-prepare: 1.0.1 => 1.0.1 
    prettier: 2.8.8 => 2.8.8 (2.3.2, 1.19.1)
    react: 18.2.0 => 18.2.0 
    react-dom: 18.2.0 => 18.2.0 
    react-native: 0.74.5 => 0.74.5 
    react-native-blurhash: ^2.0.2 => 2.0.3 
    react-native-compressor: ^1.8.24 => 1.8.25 
    react-native-device-info: ^10.13.2 => 10.14.0 
    react-native-gesture-handler: ~2.16.1 => 2.16.2 
    react-native-get-random-values: ^1.11.0 => 1.11.0 
    react-native-ios-context-menu: ^2.4.5 => 2.5.1 
    react-native-ios-utilities: ^4.4.5 => 4.5.0 
    react-native-mime-types: ^2.5.0 => 2.5.0 
    react-native-mmkv: ^2.12.2 => 2.12.2 
    react-native-reanimated: ~3.10.1 => 3.10.1 
    react-native-safe-area-context: 4.10.5 => 4.10.5 
    react-native-screens: 3.34.0 => 3.34.0 
    react-native-static-safe-area-insets: ^2.2.0 => 2.2.0 
    react-native-touchable-scale: ^2.2.0 => 2.2.0 
    react-native-url-polyfill: ^2.0.0 => 2.0.0 
    react-native-vision-camera: 4.5.0 => 4.5.0 
    react-native-vision-camera-face-detector: ^1.6.3 => 1.7.1 
    react-native-volume-manager: ^1.10.0 => 1.10.0 
    react-native-web: ~0.19.6 => 0.19.12 
    react-native-webview: 13.8.6 => 13.8.6 
    react-native-worklets-core: ^1.3.3 => 1.3.3 
    react-native-youtube-iframe: ^2.3.0 => 2.3.0 
    react-test-renderer: 18.2.0 => 18.2.0 
    reactotron-core-client: ^2.8.13 => 2.9.4 
    reactotron-mst: ^3.1.7 => 3.1.10 
    reactotron-react-js: ^3.3.11 => 3.3.15 
    reactotron-react-native: ^5.0.5 => 5.1.8 
    ts-jest: ^29.1.1 => 29.2.5 
    ts-node: ^10.9.2 => 10.9.2 
    tsx: ^4.9.4 => 4.19.0 
    typescript: ~5.3.3 => 5.3.3 (4.4.4, 4.9.5)
    uuid: ^9.0.1 => 9.0.1 (8.3.2, 3.3.2, 7.0.3)
    zeego: ^1.10.0 => 1.10.0 
  npmGlobalPackages:
    eas-cli: 11.0.2
    npm: 10.8.2

Describe the bug

Not necessarily a bug but more of a question / feature request. If I have relational data like so:

User: a
    .model({
      id: a.id().required(),
      birthdate: a.string().required(),
      email: a.email().required(),
      firstName: a.string().required(),
      lastName: a.string().required(),
      username: a.string().required(),
      phoneNumber: a.hasOne("PhoneNumber", "userId"),
      pushToken: a.string(),
      profileImageS3Path: a.string(),
      profileImageBlurhash: a.string(),
      groups: a.hasMany("UserGroup", "userId"),
      status: a.ref("UserStatus").required(),
      sentFriendships: a.hasMany("Friendship", "senderId"),
      receivedFriendships: a.hasMany("Friendship", "receiverId"),
      recents: a.hasMany("Recent", "ownerId"),
    })
    .secondaryIndexes((index) => [
      index("status").queryField("listActiveUsersByFirstName").sortKeys(["firstName"]),
      index("email").name("byEmail").queryField("listUsersByEmail"),
    ])
    .authorization((allow) => [allow.publicApiKey().to(["read"]), allow.authenticated()]),
Friendship: a
    .model({
      id: a.id().required(),
      receiverId: a.id().required(),
      receiver: a.belongsTo("User", "receiverId"),
      senderId: a.id().required(),
      sender: a.belongsTo("User", "senderId"),
      status: a.ref("FriendStatus").required(),
      recents: a.hasMany("Recent", "friendshipId"),
      owners: a.string().array(),
    })

    .secondaryIndexes((index) => [
      index("senderId")
        .name("bySenderId")
        .sortKeys(["receiverId"])
        .queryField("listFriendshipsBySenderId"),
      index("receiverId")
        .name("byReceiverId")
        .sortKeys(["senderId"])
        .queryField("listFriendshipsByReceiverId"),
    ])
    .authorization((allow) => [
      allow.authenticated().to(["read"]),
      allow.ownersDefinedIn("owners"),
    ]),
  Group: a
    .model({
      id: a.id().required(),
      name: a.string().required(),
      groupImageS3Path: a.string().required(),
      groupImageBlurhash: a.string().required(),
      users: a.hasMany("UserGroup", "groupId"),
      reelFeels: a.hasMany("ReelFeel", "groupId"),
      recents: a.hasMany("Recent", "groupId"),
      owners: a.string().array(),
    })
    .authorization((allow) => [
      allow.authenticated().to(["read"]),
      allow.ownersDefinedIn("owners"),
    ]),

Where a friendship has users and so does groups, and they are linked together through hasMany relationships. When I delete a user, can I make it automatically delete friendships and groups for instance with that user in it?

I find it very annoying code wise such that every time I'm going to delete a user, I have to:

  1. Query all Friendship objects with that user
  2. Delete all Friendship objects with that user
  3. Query all Group objects with that user
  4. Delete all Group objects with that user
  5. Query all Post objects with that user
  6. Delete all Post objects with that user
  7. Delete the user FINALLY

Is there a way to make it to where, they I can just say client.models.User.delete and then it automatically deletes all related data?

Expected behavior

N/A Mentioned above.

Reproduction steps

N/A

Code Snippet

See above

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

iPhone 12

Mobile Operating System

iOS 17

Mobile Browser

Safari

Mobile Browser Version

N/A

Additional information and screenshots

No response

@github-actions github-actions bot added the pending-triage Issue is pending triage label Aug 30, 2024
@ChristopherGabba
Copy link
Author

Apologies, should've done some more searching. This has been requested as a feature for quite some time. 3 years.
aws-amplify/amplify-category-api#273

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-triage Issue is pending triage
Projects
None yet
Development

No branches or pull requests

1 participant