Commit ab8a75d0 authored by Alexandros Georgantas's avatar Alexandros Georgantas

Merge branch 'datamodel-additions' into 'master'

Datamodel additions

See merge request editoria/editoria!140
parents 961970da 52cef1e1
/*
INHERITED
---
id
created
updated
deleted
FOREIGN
---
foreignId
*/
// TO DO make sure we want foreignType && foreignId ??
const Base = require('../editoriaBase')
const {
arrayOfStringsNotEmpty,
foreignType,
id,
integerPositive,
mimetype,
stringNotEmpty,
uri,
} = require('../helpers').schema
class File extends Base {
constructor(properties) {
super(properties)
this.type = 'file'
}
static get tableName() {
return 'File'
}
static get schema() {
return {
filename: stringNotEmpty,
foreignId: id,
foreignType,
mimetype,
referenceId: id,
size: integerPositive,
source: uri,
tags: arrayOfStringsNotEmpty,
}
}
}
module.exports = File
/*
FOREIGN
---
languageId
fileId
*/
const Base = require('../editoriaBase')
const { string } = require('../helpers').schema
class FileTranslation extends Base {
constructor(properties) {
super(properties)
this.type = 'fileTranslation'
}
static get tableName() {
return 'FileTranslation'
}
static get schema() {
return {
alt: string,
description: string,
}
}
}
module.exports = FileTranslation
......@@ -10,8 +10,7 @@ const { Model } = require('objection')
const uuid = require('uuid/v4')
const Base = require('../editoriaBase')
const { model: Book } = require('../book')
const { model: Division } = require('../division')
const {
boolean,
booleanDefaultFalse,
......@@ -31,6 +30,10 @@ class BookComponent extends Base {
}
static get relationMappings() {
const { model: Book } = require('../book')
const { model: Division } = require('../division')
const { model: BookComponentState } = require('../bookComponentState')
return {
book: {
relation: Model.BelongsToOneRelation,
......@@ -48,6 +51,14 @@ class BookComponent extends Base {
to: 'Division.id',
},
},
bookComponentState: {
relation: Model.BelongsToOneRelation,
modelClass: BookComponentState,
join: {
from: 'BookComponent.id',
to: 'BookComponentState.bookComponentId',
},
},
}
}
......@@ -106,6 +117,9 @@ class BookComponent extends Base {
getDivision() {
return this.$relatedQuery('division')
}
getBookComponentState() {
return this.$relatedQuery('bookComponentState')
}
}
module.exports = BookComponent
......@@ -13,7 +13,7 @@ const { Model } = require('objection')
const Base = require('../editoriaBase')
const { model: BookComponent } = require('../bookComponent')
const { array, booleanDefaultFalse, id } = require('../helpers').schema
const { array, booleanDefaultFalse, id, string } = require('../helpers').schema
class BookComponentState extends Base {
constructor(properties) {
......@@ -63,6 +63,9 @@ class BookComponentState extends Base {
},
trackChangesEnabled: booleanDefaultFalse,
uploading: booleanDefaultFalse,
includeInTOC: booleanDefaultFalse,
runningHeadersRight: string,
runningHeadersLeft: string,
// left loose on purpose to allow for configurability
workflowStages: array,
},
......
exports.up = async knex =>
knex.schema.table('book_component_state', table => {
table.string('runningHeadersRight')
table.string('runningHeadersLeft')
table.boolean('includeInTOC')
})
......@@ -41,6 +41,7 @@ class Division extends Base {
static get relationMappings() {
const { model: Book } = require('../book')
const { model: BookComponent } = require('../bookComponent')
return {
book: {
......@@ -51,12 +52,23 @@ class Division extends Base {
to: 'Book.id',
},
},
bookComponents: {
relation: Model.HasManyRelation,
modelClass: BookComponent,
join: {
from: 'BookComponent.divisionId',
to: 'Division.id',
},
},
}
}
getBook() {
return this.$relatedQuery('book')
}
getBookComponents() {
return this.$relatedQuery('bookComponents')
}
}
module.exports = Division
const { Model } = require('objection')
const Base = require('../editoriaBase')
const {
arrayOfStringsNotEmpty,
foreignType,
id,
integerPositive,
mimetype,
stringNotEmpty,
uri,
} = require('../helpers').schema
class File extends Base {
constructor(properties) {
super(properties)
this.type = 'file'
}
static get tableName() {
return 'File'
}
static get relationMappings() {
const { model: Book } = require('../book')
const { model: BookComponent } = require('../bookComponent')
const { model: FileTranslation } = require('../fileTranslation')
const { model: Template } = require('../template')
return {
book: {
relation: Model.BelongsToOneRelation,
modelClass: Book,
join: {
from: 'File.bookId',
to: 'Book.id',
},
},
bookComponent: {
relation: Model.BelongsToOneRelation,
modelClass: BookComponent,
join: {
from: 'File.bookComponentId',
to: 'BookComponent.id',
},
},
template: {
relation: Model.BelongsToOneRelation,
modelClass: Template,
join: {
from: 'File.templateId',
to: 'Template.id',
},
},
fileTranslations: {
relation: Model.HasManyRelation,
modelClass: FileTranslation,
join: {
from: 'File.id',
to: 'FileTranslation.fileId',
},
},
}
}
static get schema() {
return {
type: 'object',
required: ['filename', 'source'],
properties: {
filename: stringNotEmpty,
bookId: id,
bookComponentId: id,
templateId: id,
foreignType,
mimetype,
referenceId: id,
size: integerPositive,
source: uri,
tags: arrayOfStringsNotEmpty,
},
}
}
getBook() {
return this.$relatedQuery('book')
}
getBookComponent() {
return this.$relatedQuery('bookComponent')
}
getFileTranslations() {
return this.$relatedQuery('fileTranslations')
}
getTemplate() {
return this.$relatedQuery('template')
}
}
module.exports = File
const model = require('./file')
module.exports = {
model,
modelName: 'File',
}
create table file (
-- base
id uuid primary key,
type text not null,
created timestamp with time zone not null default current_timestamp,
updated timestamp with time zone,
-- editoria base
deleted boolean default false,
--foreign
book_id uuid references book,
book_component_id uuid references bookComponent
template_id uuid references template,
reference_id uuid not null,
size int,
foreign_type text,
mimetype text,
source text,
tags text[],
filename text not null
);
\ No newline at end of file
const { string } = require('../helpers').schema
const { Model } = require('objection')
const Translation = require('../translation')
const { id } = require('../helpers').schema
class FileTranslation extends Translation {
constructor(properties) {
super(properties)
this.type = 'fileTranslation'
}
static get tableName() {
return 'FileTranslation'
}
static get relationMappings() {
const { model: File } = require('../file')
return {
file: {
relation: Model.BelongsToOneRelation,
modelClass: File,
join: {
from: 'FileTranslation.fileId',
to: 'File.id',
},
},
}
}
static get schema() {
return {
type: 'object',
required: ['fileId'],
properties: {
fileId: id,
alt: string,
description: string,
},
}
}
getFile() {
return this.$relatedQuery('file')
}
}
module.exports = FileTranslation
const model = require('./fileTranslation')
module.exports = {
model,
modelName: 'FileTranslation',
}
create table file_translation
(
-- base
id uuid primary key,
type text not null,
created timestamp
with time zone not null default current_timestamp,
updated timestamp
with time zone,
-- editoria base
deleted boolean default false,
-- translation
language_iso text not null,
-- foreign
file_id uuid not null references file,
-- own
alt text,
description text,
-- constraints
unique
(file_id, language_iso)
);
......@@ -272,6 +272,10 @@ const schema = {
type: 'integer',
exclusiveMinimum: 0,
},
targetType: {
type: 'string',
enum: ['epub', 'pagedjs', 'vivliostyle'],
},
language: {
regexp: {
pattern: langIsoRegex,
......
......@@ -5,6 +5,9 @@ const bookComponent = require('./bookComponent')
const bookComponentState = require('./bookComponentState')
const bookComponentTranslation = require('./bookComponentTranslation')
const bookTranslation = require('./bookTranslation')
const file = require('./file')
const fileTranslation = require('./fileTranslation')
const template = require('./template')
const division = require('./division')
const team = require('./team')
const user = require('./user')
......@@ -24,8 +27,11 @@ module.exports = {
bookComponentTranslation,
bookTranslation,
division,
file,
fileTranslation,
lock,
loader,
template,
models: {
Book: book.model,
BookCollection: bookCollection.model,
......@@ -35,7 +41,10 @@ module.exports = {
BookComponentTranslation: bookComponentTranslation.model,
BookTranslation: bookTranslation.model,
Division: division.model,
File: file.model,
FileTranslation: fileTranslation.model,
Team: team.model,
Template: template.model,
User: user.model,
Lock: lock.model,
loader,
......
const model = require('./template')
module.exports = {
model,
modelName: 'Template',
}
create table template (
-- base
id uuid primary key,
type text not null,
created timestamp with time zone not null default current_timestamp,
updated timestamp with time zone,
-- editoria base
deleted boolean default false,
reference_id uuid,
author text,
thumbnail_id uuid references file,
templateName text not null
target string,
files text[],
);
\ No newline at end of file
const { Model } = require('./node_modules/objection')
const Base = require('../editoriaBase')
const { arrayOfIds, id, stringNotEmpty, string, targetType } = require('../helpers').schema
class Template extends Base {
constructor(properties) {
super(properties)
this.type = 'template'
}
static get tableName() {
return 'Template'
}
static get schema() {
return {
type: 'object',
required: ['templateName'],
properties: {
templateName: stringNotEmpty,
referenceId: id,
author: string,
thumbnailId: id,
files: arrayOfIds,
target: targetType,
},
}
}
static get relationMappings() {
const { model: File } = require('../file')
return {
files: {
relation: Model.HasManyRelation,
modelClass: File,
join: {
from: 'File.templateId',
to: 'Template.id',
},
},
thumbnail: {
relation: Model.BelongsToOneRelation,
modelClass: File,
join: {
from: 'Template.thumbnailId',
to: 'File.id',
},
},
}
}
getFiles() {
return this.$relatedQuery('files')
}
getThumbnail() {
return this.$relatedQuery('thumbnail')
}
}
module.exports = Template
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment