Skip to content

Commit

Permalink
Desktop, Cli, Mobile: Migrate profile in preparation for trash feature
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Feb 12, 2024
1 parent 012fe0f commit 115eb5d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 62 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Expand Up @@ -801,6 +801,7 @@ packages/lib/services/database/migrations/42.js
packages/lib/services/database/migrations/43.js
packages/lib/services/database/migrations/44.js
packages/lib/services/database/migrations/45.js
packages/lib/services/database/migrations/46.js
packages/lib/services/database/migrations/index.js
packages/lib/services/database/sqlStringToLines.js
packages/lib/services/database/types.js
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -781,6 +781,7 @@ packages/lib/services/database/migrations/42.js
packages/lib/services/database/migrations/43.js
packages/lib/services/database/migrations/44.js
packages/lib/services/database/migrations/45.js
packages/lib/services/database/migrations/46.js
packages/lib/services/database/migrations/index.js
packages/lib/services/database/sqlStringToLines.js
packages/lib/services/database/types.js
Expand Down
26 changes: 26 additions & 0 deletions packages/lib/services/database/migrations/46.ts
@@ -0,0 +1,26 @@
import { SqlQuery } from '../types';

export default (): (SqlQuery|string)[] => {
return [
'ALTER TABLE `notes` ADD COLUMN `deleted_time` INT NOT NULL DEFAULT 0',
'ALTER TABLE `folders` ADD COLUMN `deleted_time` INT NOT NULL DEFAULT 0',
'DROP VIEW tags_with_note_count',
`
CREATE VIEW tags_with_note_count AS
SELECT
tags.id as id,
tags.title as title,
tags.created_time as created_time,
tags.updated_time as updated_time,
COUNT(notes.id) as note_count,
SUM(CASE WHEN notes.todo_completed > 0 THEN 1 ELSE 0 END) AS todo_completed_count
FROM tags
LEFT JOIN note_tags nt on nt.tag_id = tags.id
LEFT JOIN notes on notes.id = nt.note_id
WHERE
notes.id IS NOT NULL
AND notes.deleted_time = 0
GROUP BY tags.id
`,
];
};
2 changes: 2 additions & 0 deletions packages/lib/services/database/migrations/index.ts
Expand Up @@ -3,6 +3,7 @@ import migration42 from './42';
import migration43 from './43';
import migration44 from './44';
import migration45 from './45';
import migration46 from './46';

import { Migration } from '../types';

Expand All @@ -11,6 +12,7 @@ const index: Migration[] = [
migration43,
migration44,
migration45,
migration46,
];

export default index;
Expand Down
74 changes: 13 additions & 61 deletions packages/lib/services/database/types.ts
Expand Up @@ -76,58 +76,6 @@ interface DatabaseTables {
[key: string]: DatabaseTable;
}





















































// AUTO-GENERATED BY packages/tools/generate-database-types.js

/*
Expand All @@ -150,6 +98,7 @@ export interface DeletedItemEntity {
}
export interface FolderEntity {
'created_time'?: number;
'deleted_time'?: number;
'encryption_applied'?: number;
'encryption_cipher_text'?: string;
'icon'?: string;
Expand Down Expand Up @@ -272,6 +221,7 @@ export interface NoteEntity {
'body'?: string;
'conflict_original_id'?: string;
'created_time'?: number;
'deleted_time'?: number;
'encryption_applied'?: number;
'encryption_cipher_text'?: string;
'id'?: string | null;
Expand Down Expand Up @@ -425,6 +375,7 @@ export interface VersionEntity {
export const databaseSchema: DatabaseTables = {
folders: {
created_time: { type: 'number' },
deleted_time: { type: 'number' },
encryption_applied: { type: 'number' },
encryption_cipher_text: { type: 'string' },
icon: { type: 'string' },
Expand Down Expand Up @@ -605,6 +556,7 @@ export const databaseSchema: DatabaseTables = {
body: { type: 'string' },
conflict_original_id: { type: 'string' },
created_time: { type: 'number' },
deleted_time: { type: 'number' },
encryption_applied: { type: 'number' },
encryption_cipher_text: { type: 'string' },
id: { type: 'string' },
Expand Down Expand Up @@ -646,15 +598,6 @@ export const databaseSchema: DatabaseTables = {
user_updated_time: { type: 'number' },
type_: { type: 'number' },
},
tags_with_note_count: {
created_time: { type: 'number' },
id: { type: 'string' },
note_count: { type: 'any' },
title: { type: 'string' },
todo_completed_count: { type: 'any' },
updated_time: { type: 'number' },
type_: { type: 'number' },
},
items_normalized: {
body: { type: 'string' },
id: { type: 'number' },
Expand Down Expand Up @@ -709,4 +652,13 @@ export const databaseSchema: DatabaseTables = {
value: { type: 'any' },
type_: { type: 'number' },
},
tags_with_note_count: {
created_time: { type: 'number' },
id: { type: 'string' },
note_count: { type: 'any' },
title: { type: 'string' },
todo_completed_count: { type: 'any' },
updated_time: { type: 'number' },
type_: { type: 'number' },
},
};
2 changes: 1 addition & 1 deletion packages/lib/services/plugins/api/noteListType.ts
Expand Up @@ -3,7 +3,7 @@
import { Size } from './types';

// AUTO-GENERATED by generate-database-type
type ListRendererDatabaseDependency = 'folder.created_time' | 'folder.encryption_applied' | 'folder.encryption_cipher_text' | 'folder.icon' | 'folder.id' | 'folder.is_shared' | 'folder.master_key_id' | 'folder.parent_id' | 'folder.share_id' | 'folder.title' | 'folder.updated_time' | 'folder.user_created_time' | 'folder.user_data' | 'folder.user_updated_time' | 'folder.type_' | 'note.altitude' | 'note.application_data' | 'note.author' | 'note.body' | 'note.conflict_original_id' | 'note.created_time' | 'note.encryption_applied' | 'note.encryption_cipher_text' | 'note.id' | 'note.is_conflict' | 'note.is_shared' | 'note.is_todo' | 'note.latitude' | 'note.longitude' | 'note.markup_language' | 'note.master_key_id' | 'note.order' | 'note.parent_id' | 'note.share_id' | 'note.source' | 'note.source_application' | 'note.source_url' | 'note.title' | 'note.todo_completed' | 'note.todo_due' | 'note.updated_time' | 'note.user_created_time' | 'note.user_data' | 'note.user_updated_time' | 'note.type_';
type ListRendererDatabaseDependency = 'folder.created_time' | 'folder.deleted_time' | 'folder.encryption_applied' | 'folder.encryption_cipher_text' | 'folder.icon' | 'folder.id' | 'folder.is_shared' | 'folder.master_key_id' | 'folder.parent_id' | 'folder.share_id' | 'folder.title' | 'folder.updated_time' | 'folder.user_created_time' | 'folder.user_data' | 'folder.user_updated_time' | 'folder.type_' | 'note.altitude' | 'note.application_data' | 'note.author' | 'note.body' | 'note.conflict_original_id' | 'note.created_time' | 'note.deleted_time' | 'note.encryption_applied' | 'note.encryption_cipher_text' | 'note.id' | 'note.is_conflict' | 'note.is_shared' | 'note.is_todo' | 'note.latitude' | 'note.longitude' | 'note.markup_language' | 'note.master_key_id' | 'note.order' | 'note.parent_id' | 'note.share_id' | 'note.source' | 'note.source_application' | 'note.source_url' | 'note.title' | 'note.todo_completed' | 'note.todo_due' | 'note.updated_time' | 'note.user_created_time' | 'note.user_data' | 'note.user_updated_time' | 'note.type_';
// AUTO-GENERATED by generate-database-type

export enum ItemFlow {
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/utils/testing/testUtils.ts
Expand Up @@ -554,6 +554,7 @@ share_id: ${note.share_id || ''}
conflict_original_id:
master_key_id:
user_data:
deleted_time: 0
type_: 1`;
}

Expand Down

0 comments on commit 115eb5d

Please sign in to comment.