aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/client/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/db')
-rw-r--r--src/client/db/index.test.ts4
-rw-r--r--src/client/db/index.ts16
-rw-r--r--src/client/db/repositories.test.ts26
-rw-r--r--src/client/db/repositories.ts7
4 files changed, 41 insertions, 12 deletions
diff --git a/src/client/db/index.test.ts b/src/client/db/index.test.ts
index a30f94b..0a4882d 100644
--- a/src/client/db/index.test.ts
+++ b/src/client/db/index.test.ts
@@ -132,8 +132,8 @@ describe("KiokuDatabase", () => {
const testCard: LocalCard = {
id: "card-1",
deckId: "deck-1",
- noteId: null,
- isReversed: null,
+ noteId: "test-note-id",
+ isReversed: false,
front: "Question",
back: "Answer",
state: CardState.New,
diff --git a/src/client/db/index.ts b/src/client/db/index.ts
index 5318b17..53df476 100644
--- a/src/client/db/index.ts
+++ b/src/client/db/index.ts
@@ -122,8 +122,8 @@ export interface LocalNoteFieldValue {
export interface LocalCard {
id: string;
deckId: string;
- noteId: string | null;
- isReversed: boolean | null;
+ noteId: string;
+ isReversed: boolean;
front: string;
back: string;
@@ -241,6 +241,18 @@ export class KiokuDatabase extends Dexie {
}
});
});
+
+ // Version 3: noteId and isReversed are now required (NOT NULL)
+ // No migration needed as production has no legacy data without notes
+ this.version(3).stores({
+ decks: "id, userId, updatedAt",
+ cards: "id, deckId, noteId, updatedAt, due, state",
+ reviewLogs: "id, cardId, userId, reviewedAt",
+ noteTypes: "id, userId, updatedAt",
+ noteFieldTypes: "id, noteTypeId, updatedAt",
+ notes: "id, deckId, noteTypeId, updatedAt",
+ noteFieldValues: "id, noteId, noteFieldTypeId, updatedAt",
+ });
}
}
diff --git a/src/client/db/repositories.test.ts b/src/client/db/repositories.test.ts
index 2fca210..da0f0d3 100644
--- a/src/client/db/repositories.test.ts
+++ b/src/client/db/repositories.test.ts
@@ -240,6 +240,8 @@ describe("localCardRepository", () => {
it("should create a card with FSRS defaults", async () => {
const card = await localCardRepository.create({
deckId,
+ noteId: "test-note-id",
+ isReversed: false,
front: "Question",
back: "Answer",
});
@@ -260,8 +262,8 @@ describe("localCardRepository", () => {
describe("findByDeckId", () => {
it("should return all cards for a deck", async () => {
- await localCardRepository.create({ deckId, front: "Q1", back: "A1" });
- await localCardRepository.create({ deckId, front: "Q2", back: "A2" });
+ await localCardRepository.create({ deckId, noteId: "test-note-id", isReversed: false, front: "Q1", back: "A1" });
+ await localCardRepository.create({ deckId, noteId: "test-note-id-2", isReversed: false, front: "Q2", back: "A2" });
const cards = await localCardRepository.findByDeckId(deckId);
expect(cards).toHaveLength(2);
@@ -270,6 +272,8 @@ describe("localCardRepository", () => {
it("should exclude soft-deleted cards", async () => {
const card = await localCardRepository.create({
deckId,
+ noteId: "test-note-id",
+ isReversed: false,
front: "Q",
back: "A",
});
@@ -287,6 +291,8 @@ describe("localCardRepository", () => {
const card1 = await localCardRepository.create({
deckId,
+ noteId: "test-note-id",
+ isReversed: false,
front: "Due",
back: "A",
});
@@ -294,6 +300,8 @@ describe("localCardRepository", () => {
const card2 = await localCardRepository.create({
deckId,
+ noteId: "test-note-id-2",
+ isReversed: false,
front: "Not Due",
back: "B",
});
@@ -308,6 +316,8 @@ describe("localCardRepository", () => {
for (let i = 0; i < 5; i++) {
await localCardRepository.create({
deckId,
+ noteId: `test-note-id-${i}`,
+ isReversed: false,
front: `Q${i}`,
back: `A${i}`,
});
@@ -322,12 +332,16 @@ describe("localCardRepository", () => {
it("should return only new cards", async () => {
await localCardRepository.create({
deckId,
+ noteId: "test-note-id",
+ isReversed: false,
front: "New",
back: "A",
});
const reviewedCard = await localCardRepository.create({
deckId,
+ noteId: "test-note-id-2",
+ isReversed: false,
front: "Reviewed",
back: "B",
});
@@ -343,6 +357,8 @@ describe("localCardRepository", () => {
it("should update card content", async () => {
const card = await localCardRepository.create({
deckId,
+ noteId: "test-note-id",
+ isReversed: false,
front: "Original",
back: "Original",
});
@@ -362,6 +378,8 @@ describe("localCardRepository", () => {
it("should update FSRS scheduling data", async () => {
const card = await localCardRepository.create({
deckId,
+ noteId: "test-note-id",
+ isReversed: false,
front: "Q",
back: "A",
});
@@ -391,6 +409,8 @@ describe("localCardRepository", () => {
it("should soft delete a card", async () => {
const card = await localCardRepository.create({
deckId,
+ noteId: "test-note-id",
+ isReversed: false,
front: "Q",
back: "A",
});
@@ -423,6 +443,8 @@ describe("localReviewLogRepository", () => {
const card = await localCardRepository.create({
deckId,
+ noteId: "test-note-id",
+ isReversed: false,
front: "Q",
back: "A",
});
diff --git a/src/client/db/repositories.ts b/src/client/db/repositories.ts
index 104f026..e01254e 100644
--- a/src/client/db/repositories.ts
+++ b/src/client/db/repositories.ts
@@ -176,8 +176,6 @@ export const localCardRepository = {
data: Omit<
LocalCard,
| "id"
- | "noteId"
- | "isReversed"
| "state"
| "due"
| "stability"
@@ -192,14 +190,11 @@ export const localCardRepository = {
| "deletedAt"
| "syncVersion"
| "_synced"
- > &
- Partial<Pick<LocalCard, "noteId" | "isReversed">>,
+ >,
): Promise<LocalCard> {
const now = new Date();
const card: LocalCard = {
id: uuidv4(),
- noteId: null,
- isReversed: null,
...data,
state: CardState.New,
due: now,