Skip to content

Commit

Permalink
Server: Rename "ReadOnly" mode to "ReadAndClear" to avoid any confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Nov 11, 2021
1 parent ec8b9b8 commit 5cd4537
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/server/src/models/ItemModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ export default class ItemModel extends BaseModel<Item> {
await storageDriver.write(itemId, content, context);

if (storageDriverFallback) {
if (storageDriverFallback.mode === StorageDriverMode.ReadWrite) {
if (storageDriverFallback.mode === StorageDriverMode.ReadAndWrite) {
await storageDriverFallback.write(itemId, content, context);
} else if (storageDriverFallback.mode === StorageDriverMode.ReadOnly) {
} else if (storageDriverFallback.mode === StorageDriverMode.ReadAndClear) {
await storageDriverFallback.write(itemId, Buffer.from(''), context);
} else {
throw new Error(`Unsupported fallback mode: ${storageDriverFallback.mode}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class StorageDriverBase {
}

public get mode(): StorageDriverMode {
return this.config.mode || StorageDriverMode.ReadOnly;
return this.config.mode || StorageDriverMode.ReadAndClear;
}

public async write(_itemId: string, _content: Buffer, _context: Context): Promise<void> { throw new Error('Not implemented'); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('StorageDriverDatabase', function() {
});

test('should support fallback content drivers in rw mode', async function() {
await shouldSupportFallbackDriverInReadWriteMode(newConfig(), { type: StorageDriverType.Memory, mode: StorageDriverMode.ReadWrite });
await shouldSupportFallbackDriverInReadWriteMode(newConfig(), { type: StorageDriverType.Memory, mode: StorageDriverMode.ReadAndWrite });
});

test('should update content storage ID after switching driver', async function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const parseType = (type: string): StorageDriverType => {
};

const parseMode = (mode: string): StorageDriverMode => {
if (mode === 'rw') return StorageDriverMode.ReadWrite;
if (mode === 'r') return StorageDriverMode.ReadOnly;
if (mode === 'ReadAndWrite') return StorageDriverMode.ReadAndWrite;
if (mode === 'ReadAndClear') return StorageDriverMode.ReadAndClear;
throw new Error(`Invalid type: "${mode}"`);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const serializeType = (type: StorageDriverType): string => {
};

const serializeMode = (mode: StorageDriverMode): string => {
if (mode === StorageDriverMode.ReadWrite) return 'rw';
if (mode === StorageDriverMode.ReadOnly) return 'r';
if (mode === StorageDriverMode.ReadAndWrite) return 'ReadAndWrite';
if (mode === StorageDriverMode.ReadAndClear) return 'ReadAndClear';
throw new Error(`Invalid type: "${mode}"`);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/models/items/storage/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export async function shouldSupportFallbackDriver(driverConfig: StorageDriverCon
}

export async function shouldSupportFallbackDriverInReadWriteMode(driverConfig: StorageDriverConfig, fallbackDriverConfig: StorageDriverConfig) {
if (fallbackDriverConfig.mode !== StorageDriverMode.ReadWrite) throw new Error('Content driver must be configured in RW mode for this test');
if (fallbackDriverConfig.mode !== StorageDriverMode.ReadAndWrite) throw new Error('Content driver must be configured in RW mode for this test');

const { user } = await createUserAndSession(1);

Expand Down
20 changes: 10 additions & 10 deletions packages/server/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,19 @@ export enum StorageDriverType {
// When writing, the app writes to the main driver. Then the mode determines how
// it writes to the fallback driver:
//
// - In read-only mode, it's going to clear the fallback driver content. This is
// used to migrate from one driver to another. It means that over time the old
// storage will be cleared and all content will be on the new storage.
// - In ReadAndClear mode, it's going to clear the fallback driver content. This
// is used to migrate from one driver to another. It means that over time the
// old storage will be cleared and all content will be on the new storage.
//
// - In read/write mode, it's going to write the content to the fallback driver.
// This is purely for safey - it allows deploying the new storage (such as the
// filesystem or S3) but still keep the old content up-to-date. So if
// something goes wrong it's possible to go back to the old storage until the
// new one is working.
// - In ReadAndWrite mode, it's going to write the content to the fallback
// driver too. This is purely for safey - it allows deploying the new storage
// (such as the filesystem or S3) but still keep the old content up-to-date.
// So if something goes wrong it's possible to go back to the old storage
// until the new one is working.

export enum StorageDriverMode {
ReadWrite = 1,
ReadOnly = 2,
ReadAndWrite = 1,
ReadAndClear = 2,
}

export interface StorageDriverConfig {
Expand Down

0 comments on commit 5cd4537

Please sign in to comment.