Skip to content

Commit

Permalink
chore: use db model instead of content type (#19563)
Browse files Browse the repository at this point in the history
* chore: use db model instead of content type

* chore: remove content type ref in comment

* fix: remove contentTypes from CM index

* fix: yet another model import

* fix: mark feedback
  • Loading branch information
remidej committed Feb 21, 2024
1 parent 65cafcb commit ab39246
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 76 deletions.
1 change: 1 addition & 0 deletions packages/core/content-manager/package.json
Expand Up @@ -56,6 +56,7 @@
"qs": "6.11.1"
},
"devDependencies": {
"@strapi/database": "workspace:*",
"@strapi/pack-up": "workspace:*",
"@types/jest": "29.5.2",
"@types/lodash": "^4.14.191",
Expand Down

This file was deleted.

This file was deleted.

14 changes: 10 additions & 4 deletions packages/core/content-manager/server/src/history/index.ts
@@ -1,9 +1,9 @@
import type { Plugin } from '@strapi/types';
import { controllers } from './controllers';
import { services } from './services';
import { contentTypes } from './content-types';
import { routes } from './routes';
import { getService } from './utils';
import { historyVersion } from './models/history-version';

/**
* Check once if the feature is enabled (both license info & feature flag) before loading it,
Expand All @@ -13,22 +13,28 @@ const getFeature = (): Partial<Plugin.LoadedPlugin> => {
// TODO: add license check here when it's ready on the license registry
if (strapi.features.future.isEnabled('history')) {
return {
register({ strapi }) {
strapi.get('models').add(historyVersion);
},
bootstrap({ strapi }) {
// Start recording history and saving history versions
getService(strapi, 'history').init();
},
controllers,
services,
contentTypes,
routes,
};
}

/**
* Keep returning contentTypes to avoid losing the data if the feature is disabled,
* Keep registering the model to avoid losing the data if the feature is disabled,
* or if the license expires.
*/
return { contentTypes };
return {
register({ strapi }) {
strapi.get('models').add(historyVersion);
},
};
};

export default getFeature();
@@ -0,0 +1,48 @@
import type { Model } from '@strapi/database';
import { HISTORY_VERSION_UID } from '../constants';

const historyVersion: Model = {
uid: HISTORY_VERSION_UID,
tableName: 'strapi_history_versions',
singularName: 'history-version',
attributes: {
id: {
type: 'increments',
},
contentType: {
type: 'string',
column: { notNullable: true },
},
relatedDocumentId: {
type: 'string',
column: { notNullable: true },
},
locale: {
type: 'string',
},
status: {
type: 'enumeration',
enum: ['draft', 'published', 'modified'],
},
data: {
type: 'json',
},
schema: {
type: 'json',
},
createdAt: {
type: 'datetime',
default: () => new Date(),
},
// FIXME: joinTable should be optional
// @ts-expect-error database model is not yet updated to support useJoinTable
createdBy: {
type: 'relation',
relation: 'oneToOne',
target: 'admin::user',
useJoinTable: false,
},
},
};

export { historyVersion };
2 changes: 0 additions & 2 deletions packages/core/content-manager/server/src/index.ts
Expand Up @@ -5,7 +5,6 @@ import routes from './routes';
import policies from './policies';
import controllers from './controllers';
import services from './services';
import history from './history';

export default () => {
return {
Expand All @@ -16,6 +15,5 @@ export default () => {
routes,
policies,
services,
contentTypes: history.contentTypes,
};
};
2 changes: 2 additions & 0 deletions packages/core/database/src/types/index.ts
Expand Up @@ -6,6 +6,7 @@ export type ID = string | number;
export interface ColumnInfo {
unsigned?: boolean;
defaultTo?: unknown;
notNullable?: boolean;
}

export type Attribute = ScalarAttribute | RelationalAttribute;
Expand Down Expand Up @@ -34,6 +35,7 @@ export interface BaseAttribute {
args: unknown[];
};
searchable?: boolean;
enum?: string[];
}

export interface ScalarAttribute extends BaseAttribute {
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Expand Up @@ -9478,7 +9478,7 @@ __metadata:
languageName: unknown
linkType: soft

"@strapi/database@npm:4.20.1, @strapi/database@workspace:packages/core/database":
"@strapi/database@npm:4.20.1, @strapi/database@workspace:*, @strapi/database@workspace:packages/core/database":
version: 0.0.0-use.local
resolution: "@strapi/database@workspace:packages/core/database"
dependencies:
Expand Down Expand Up @@ -9778,6 +9778,7 @@ __metadata:
resolution: "@strapi/plugin-content-manager@workspace:packages/core/content-manager"
dependencies:
"@sindresorhus/slugify": "npm:1.1.0"
"@strapi/database": "workspace:*"
"@strapi/pack-up": "workspace:*"
"@strapi/types": "npm:4.20.1"
"@strapi/utils": "npm:4.20.1"
Expand Down

0 comments on commit ab39246

Please sign in to comment.