Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
488 changes: 488 additions & 0 deletions app/schemas/me.ash.reader.infrastructure.db.AndroidDatabase/10.json

Large diffs are not rendered by default.

510 changes: 510 additions & 0 deletions app/schemas/me.ash.reader.infrastructure.db.AndroidDatabase/8.json

Large diffs are not rendered by default.

488 changes: 488 additions & 0 deletions app/schemas/me.ash.reader.infrastructure.db.AndroidDatabase/9.json

Large diffs are not rendered by default.

14 changes: 1 addition & 13 deletions app/src/main/java/me/ash/reader/domain/model/feed/Feed.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
package me.ash.reader.domain.model.feed

import androidx.room.*
import me.ash.reader.domain.model.group.Group

/**
* TODO: Add class description
*/
@Entity(
tableName = "feed",
foreignKeys = [ForeignKey(
entity = Group::class,
parentColumns = ["id"],
childColumns = ["groupId"],
onDelete = ForeignKey.CASCADE,
onUpdate = ForeignKey.CASCADE,
)],
)
data class Feed(
@PrimaryKey
Expand All @@ -25,8 +14,7 @@ data class Feed(
val icon: String? = null,
@ColumnInfo
val url: String,
@ColumnInfo(index = true)
var groupId: String,
var groupId: String = "",
@ColumnInfo(index = true)
val accountId: Int,
@ColumnInfo
Expand Down
15 changes: 0 additions & 15 deletions app/src/main/java/me/ash/reader/domain/model/feed/FeedWithGroup.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.ash.reader.domain.model.feed

import androidx.room.Embedded
import androidx.room.Junction
import androidx.room.Relation
import me.ash.reader.domain.model.feedgroup.FeedGroup
import me.ash.reader.domain.model.group.Group

/**
* A [feed] belongs to many [groups] via many-to-many relationship through [FeedGroup] junction table.
*
* This supports the use case where a single feed can be organized into multiple groups/folders.
*/
data class FeedWithGroups(
@Embedded
val feed: Feed,
@Relation(
parentColumn = "id",
entityColumn = "id",
associateBy = Junction(
value = FeedGroup::class,
parentColumn = "feedId",
entityColumn = "groupId"
)
)
val groups: List<Group>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package me.ash.reader.domain.model.feedgroup

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import me.ash.reader.domain.model.account.Account
import me.ash.reader.domain.model.feed.Feed
import me.ash.reader.domain.model.group.Group

/**
* Junction table to handle feeds that belong to one or more groups
*/
@Entity(
tableName = "feed_group",
primaryKeys = ["feedId", "groupId", "accountId"],
foreignKeys = [
ForeignKey(
entity = Feed::class,
parentColumns = ["id"],
childColumns = ["feedId"],
onDelete = ForeignKey.CASCADE
),
ForeignKey(
entity = Group::class,
parentColumns = ["id"],
childColumns = ["groupId"],
onDelete = ForeignKey.CASCADE
),
ForeignKey(
entity = Account::class,
parentColumns = ["id"],
childColumns = ["accountId"],
onDelete = ForeignKey.CASCADE
)
],
indices = [
Index(value = ["feedId"]),
Index(value = ["groupId"]),
Index(value = ["accountId"])
]
)
data class FeedGroup(
val feedId: String,
val groupId: String,
val accountId: Int,
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
package me.ash.reader.domain.model.group

import androidx.room.Embedded
import androidx.room.Junction
import androidx.room.Relation
import me.ash.reader.domain.model.feed.Feed
import me.ash.reader.domain.model.feedgroup.FeedGroup

/**
* A [group] contains many [feeds].
* A [group] contains many [feeds] via the [FeedGroup] junction table.
*
* This represents a many-to-many relationship where feeds can belong to multiple groups.
* The junction table ([FeedGroup]) is the source of truth for feed-group associations.
*/
data class GroupWithFeed(
@Embedded
val group: Group,
@Relation(parentColumn = "id", entityColumn = "groupId")
@Relation(
parentColumn = "id",
entityColumn = "id",
associateBy = Junction(
value = FeedGroup::class,
parentColumn = "groupId",
entityColumn = "feedId"
)
)
val feeds: MutableList<Feed>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package me.ash.reader.domain.model.group

import androidx.room.Embedded
import androidx.room.Junction
import androidx.room.Relation
import me.ash.reader.domain.model.feed.Feed
import me.ash.reader.domain.model.feedgroup.FeedGroup

/**
* A [group] contains many [feeds] via many-to-many relationship through [FeedGroup] junction table.
*
* This differs from [GroupWithFeed] which uses the legacy one-to-many relationship via Feed.groupId.
* Use this class for queries that need to support feeds belonging to multiple groups.
*/
data class GroupWithFeedViaJunction(
@Embedded
val group: Group,
@Relation(
parentColumn = "id",
entityColumn = "id",
associateBy = Junction(
value = FeedGroup::class,
parentColumn = "groupId",
entityColumn = "feedId"
)
)
val feeds: List<Feed>,
)
Loading
Loading