Ghost/core/server/data/schema/schema.js

734 lines
40 KiB
JavaScript
Raw Normal View History

/* String Column Sizes Information
* (From: https://github.com/TryGhost/Ghost/pull/7932)
*
* Small strings = length 50
* Medium strings = length 191
* Large strings = length 1000-2000
* Text = length 65535 (64 KiB)
* Long text = length 1,000,000,000
*/
module.exports = {
posts: {
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
uuid: {type: 'string', maxlength: 36, nullable: false, validations: {isUUID: true}},
title: {type: 'string', maxlength: 2000, nullable: false, validations: {isLength: {max: 255}}},
slug: {type: 'string', maxlength: 191, nullable: false},
mobiledoc: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
html: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
comment_id: {type: 'string', maxlength: 50, nullable: true},
plaintext: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
feature_image: {type: 'string', maxlength: 2000, nullable: true},
featured: {type: 'bool', nullable: false, defaultTo: false},
type: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'post', validations: {isIn: [['post', 'page']]}},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'draft'},
// NOTE: unused at the moment and reserved for future features
locale: {type: 'string', maxlength: 6, nullable: true},
✨ Multiple authors (#9426) no issue This PR adds the server side logic for multiple authors. This adds the ability to add multiple authors per post. We keep and support single authors (maybe till the next major - this is still in discussion) ### key notes - `authors` are not fetched by default, only if we need them - the migration script iterates over all posts and figures out if an author_id is valid and exists (in master we can add invalid author_id's) and then adds the relation (falls back to owner if invalid) - ~~i had to push a fork of bookshelf to npm because we currently can't bump bookshelf + the two bugs i discovered are anyway not yet merged (https://github.com/kirrg001/bookshelf/commits/master)~~ replaced by new bookshelf release - the implementation of single & multiple authors lives in a single place (introduction of a new concept: model relation) - if you destroy an author, we keep the behaviour for now -> remove all posts where the primary author id matches. furthermore, remove all relations in posts_authors (e.g. secondary author) - we make re-use of the `excludeAttrs` concept which was invented in the contributors PR (to protect editing authors as author/contributor role) -> i've added a clear todo that we need a logic to make a diff of the target relation -> both for tags and authors - `authors` helper available (same as `tags` helper) - `primary_author` computed field available - `primary_author` functionality available (same as `primary_tag` e.g. permalinks, prev/next helper etc)
2018-03-27 17:16:15 +03:00
visibility: {
type: 'string',
maxlength: 50,
nullable: false,
defaultTo: 'public'
✨ Multiple authors (#9426) no issue This PR adds the server side logic for multiple authors. This adds the ability to add multiple authors per post. We keep and support single authors (maybe till the next major - this is still in discussion) ### key notes - `authors` are not fetched by default, only if we need them - the migration script iterates over all posts and figures out if an author_id is valid and exists (in master we can add invalid author_id's) and then adds the relation (falls back to owner if invalid) - ~~i had to push a fork of bookshelf to npm because we currently can't bump bookshelf + the two bugs i discovered are anyway not yet merged (https://github.com/kirrg001/bookshelf/commits/master)~~ replaced by new bookshelf release - the implementation of single & multiple authors lives in a single place (introduction of a new concept: model relation) - if you destroy an author, we keep the behaviour for now -> remove all posts where the primary author id matches. furthermore, remove all relations in posts_authors (e.g. secondary author) - we make re-use of the `excludeAttrs` concept which was invented in the contributors PR (to protect editing authors as author/contributor role) -> i've added a clear todo that we need a logic to make a diff of the target relation -> both for tags and authors - `authors` helper available (same as `tags` helper) - `primary_author` computed field available - `primary_author` functionality available (same as `primary_tag` e.g. permalinks, prev/next helper etc)
2018-03-27 17:16:15 +03:00
},
email_recipient_filter: {
type: 'text',
maxlength: 1000000000,
nullable: false,
✨ Added ability to send a newsletter to members with a certain label or product (#12932) refs https://github.com/TryGhost/Team/issues/581 refs https://github.com/TryGhost/Team/issues/582 When publishing a post via the API it was possible to send it using `?email_recipient_filter=all/free/paid` which allowed you to send to members only based on their payment status which is quite limiting for some sites. This PR updates the `?email_recipient_filter` query param to support Ghost's `?filter` param syntax which enables more specific recipient lists, eg: `?email_recipient_filter=status:free` = free members only `?email_recipient_filter=status:paid` = paid members only `?email_recipient_filter=label:vip` = members that have the `vip` label attached `?email_recipient_filter=status:paid,label:vip` = paid members and members that have the `vip` label attached The older `free/paid` values are still supported by the API for backwards compatibility. - updates `Post` and `Email` models to transform legacy `free` and `paid` values to their NQL equivalents on read/write - lets us not worry about supporting legacy values elsewhere in the code - cleanup migration to transform all rows slated for 5.0 - removes schema and API `isIn` validations for recipient filters so allow free-form filters - updates posts API input serializers to transform `free` and `paid` values in the `?email_recipient_filter` param to their NQL equivalents for backwards compatibility - updates Post API controllers `edit` methods to run a query using the supplied filter to verify that it's valid - updates `mega` service to use the filter directly when selecting recipients
2021-05-07 13:56:41 +03:00
defaultTo: 'none'
},
✨ Multiple authors (#9426) no issue This PR adds the server side logic for multiple authors. This adds the ability to add multiple authors per post. We keep and support single authors (maybe till the next major - this is still in discussion) ### key notes - `authors` are not fetched by default, only if we need them - the migration script iterates over all posts and figures out if an author_id is valid and exists (in master we can add invalid author_id's) and then adds the relation (falls back to owner if invalid) - ~~i had to push a fork of bookshelf to npm because we currently can't bump bookshelf + the two bugs i discovered are anyway not yet merged (https://github.com/kirrg001/bookshelf/commits/master)~~ replaced by new bookshelf release - the implementation of single & multiple authors lives in a single place (introduction of a new concept: model relation) - if you destroy an author, we keep the behaviour for now -> remove all posts where the primary author id matches. furthermore, remove all relations in posts_authors (e.g. secondary author) - we make re-use of the `excludeAttrs` concept which was invented in the contributors PR (to protect editing authors as author/contributor role) -> i've added a clear todo that we need a logic to make a diff of the target relation -> both for tags and authors - `authors` helper available (same as `tags` helper) - `primary_author` computed field available - `primary_author` functionality available (same as `primary_tag` e.g. permalinks, prev/next helper etc)
2018-03-27 17:16:15 +03:00
/**
* @deprecated: single authors was superceded by multiple authors in Ghost 1.22.0
✨ Multiple authors (#9426) no issue This PR adds the server side logic for multiple authors. This adds the ability to add multiple authors per post. We keep and support single authors (maybe till the next major - this is still in discussion) ### key notes - `authors` are not fetched by default, only if we need them - the migration script iterates over all posts and figures out if an author_id is valid and exists (in master we can add invalid author_id's) and then adds the relation (falls back to owner if invalid) - ~~i had to push a fork of bookshelf to npm because we currently can't bump bookshelf + the two bugs i discovered are anyway not yet merged (https://github.com/kirrg001/bookshelf/commits/master)~~ replaced by new bookshelf release - the implementation of single & multiple authors lives in a single place (introduction of a new concept: model relation) - if you destroy an author, we keep the behaviour for now -> remove all posts where the primary author id matches. furthermore, remove all relations in posts_authors (e.g. secondary author) - we make re-use of the `excludeAttrs` concept which was invented in the contributors PR (to protect editing authors as author/contributor role) -> i've added a clear todo that we need a logic to make a diff of the target relation -> both for tags and authors - `authors` helper available (same as `tags` helper) - `primary_author` computed field available - `primary_author` functionality available (same as `primary_tag` e.g. permalinks, prev/next helper etc)
2018-03-27 17:16:15 +03:00
* If we keep it, then only, because you can easier query post.author_id than posts_authors[*].sort_order.
*/
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
author_id: {type: 'string', maxlength: 24, nullable: false},
created_at: {type: 'dateTime', nullable: false},
/**
* @deprecated: https://github.com/TryGhost/Ghost/issues/10286
*
* This is valid for all x_by fields.
*/
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
updated_by: {type: 'string', maxlength: 24, nullable: true},
published_at: {type: 'dateTime', nullable: true},
published_by: {type: 'string', maxlength: 24, nullable: true},
custom_excerpt: {type: 'string', maxlength: 2000, nullable: true, validations: {isLength: {max: 300}}},
codeinjection_head: {type: 'text', maxlength: 65535, nullable: true},
codeinjection_foot: {type: 'text', maxlength: 65535, nullable: true},
custom_template: {type: 'string', maxlength: 100, nullable: true},
canonical_url: {type: 'text', maxlength: 2000, nullable: true},
'@@UNIQUE_CONSTRAINTS@@': [
['slug', 'type']
]
},
posts_meta: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
post_id: {type: 'string', maxlength: 24, nullable: false, references: 'posts.id', unique: true},
og_image: {type: 'string', maxlength: 2000, nullable: true},
og_title: {type: 'string', maxlength: 300, nullable: true},
og_description: {type: 'string', maxlength: 500, nullable: true},
twitter_image: {type: 'string', maxlength: 2000, nullable: true},
twitter_title: {type: 'string', maxlength: 300, nullable: true},
twitter_description: {type: 'string', maxlength: 500, nullable: true},
meta_title: {type: 'string', maxlength: 2000, nullable: true, validations: {isLength: {max: 300}}},
meta_description: {type: 'string', maxlength: 2000, nullable: true, validations: {isLength: {max: 500}}},
email_subject: {type: 'string', maxlength: 300, nullable: true},
frontmatter: {type: 'text', maxlength: 65535, nullable: true},
feature_image_alt: {type: 'string', maxlength: 191, nullable: true, validations: {isLength: {max: 125}}},
feature_image_caption: {type: 'text', maxlength: 65535, nullable: true},
email_only: {type: 'bool', nullable: false, defaultTo: false}
},
users: {
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
name: {type: 'string', maxlength: 191, nullable: false},
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
password: {type: 'string', maxlength: 60, nullable: false},
email: {type: 'string', maxlength: 191, nullable: false, unique: true, validations: {isEmail: true}},
profile_image: {type: 'string', maxlength: 2000, nullable: true},
cover_image: {type: 'string', maxlength: 2000, nullable: true},
bio: {type: 'text', maxlength: 65535, nullable: true, validations: {isLength: {max: 200}}},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
website: {type: 'string', maxlength: 2000, nullable: true, validations: {isEmptyOrURL: true}},
location: {type: 'text', maxlength: 65535, nullable: true, validations: {isLength: {max: 150}}},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
facebook: {type: 'string', maxlength: 2000, nullable: true},
twitter: {type: 'string', maxlength: 2000, nullable: true},
accessibility: {type: 'text', maxlength: 65535, nullable: true},
// TODO: would be good to add validation here to control for all possible status values.
// The ones that come up by reviewing the user model are:
// 'active', 'inactive', 'locked', 'warn-1', 'warn-2', 'warn-3', 'warn-4'
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'active'},
// NOTE: unused at the moment and reserved for future features
locale: {type: 'string', maxlength: 6, nullable: true},
✨ Multiple authors (#9426) no issue This PR adds the server side logic for multiple authors. This adds the ability to add multiple authors per post. We keep and support single authors (maybe till the next major - this is still in discussion) ### key notes - `authors` are not fetched by default, only if we need them - the migration script iterates over all posts and figures out if an author_id is valid and exists (in master we can add invalid author_id's) and then adds the relation (falls back to owner if invalid) - ~~i had to push a fork of bookshelf to npm because we currently can't bump bookshelf + the two bugs i discovered are anyway not yet merged (https://github.com/kirrg001/bookshelf/commits/master)~~ replaced by new bookshelf release - the implementation of single & multiple authors lives in a single place (introduction of a new concept: model relation) - if you destroy an author, we keep the behaviour for now -> remove all posts where the primary author id matches. furthermore, remove all relations in posts_authors (e.g. secondary author) - we make re-use of the `excludeAttrs` concept which was invented in the contributors PR (to protect editing authors as author/contributor role) -> i've added a clear todo that we need a logic to make a diff of the target relation -> both for tags and authors - `authors` helper available (same as `tags` helper) - `primary_author` computed field available - `primary_author` functionality available (same as `primary_tag` e.g. permalinks, prev/next helper etc)
2018-03-27 17:16:15 +03:00
visibility: {
type: 'string',
maxlength: 50,
nullable: false,
defaultTo: 'public',
validations: {isIn: [['public']]}
},
meta_title: {type: 'string', maxlength: 2000, nullable: true, validations: {isLength: {max: 300}}},
meta_description: {type: 'string', maxlength: 2000, nullable: true, validations: {isLength: {max: 500}}},
tour: {type: 'text', maxlength: 65535, nullable: true},
last_seen: {type: 'dateTime', nullable: true},
created_at: {type: 'dateTime', nullable: false},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
oauth: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
provider: {type: 'string', maxlength: 50, nullable: false},
provider_id: {type: 'string', maxlength: 191, nullable: false},
access_token: {type: 'text', maxlength: 65535, nullable: true},
refresh_token: {type: 'text', maxlength: 2000, nullable: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true},
user_id: {type: 'string', maxlength: 24, nullable: false, references: 'users.id'}
},
✨ Multiple authors (#9426) no issue This PR adds the server side logic for multiple authors. This adds the ability to add multiple authors per post. We keep and support single authors (maybe till the next major - this is still in discussion) ### key notes - `authors` are not fetched by default, only if we need them - the migration script iterates over all posts and figures out if an author_id is valid and exists (in master we can add invalid author_id's) and then adds the relation (falls back to owner if invalid) - ~~i had to push a fork of bookshelf to npm because we currently can't bump bookshelf + the two bugs i discovered are anyway not yet merged (https://github.com/kirrg001/bookshelf/commits/master)~~ replaced by new bookshelf release - the implementation of single & multiple authors lives in a single place (introduction of a new concept: model relation) - if you destroy an author, we keep the behaviour for now -> remove all posts where the primary author id matches. furthermore, remove all relations in posts_authors (e.g. secondary author) - we make re-use of the `excludeAttrs` concept which was invented in the contributors PR (to protect editing authors as author/contributor role) -> i've added a clear todo that we need a logic to make a diff of the target relation -> both for tags and authors - `authors` helper available (same as `tags` helper) - `primary_author` computed field available - `primary_author` functionality available (same as `primary_tag` e.g. permalinks, prev/next helper etc)
2018-03-27 17:16:15 +03:00
posts_authors: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
post_id: {type: 'string', maxlength: 24, nullable: false, references: 'posts.id'},
author_id: {type: 'string', maxlength: 24, nullable: false, references: 'users.id'},
sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0}
},
roles: {
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
name: {type: 'string', maxlength: 50, nullable: false, unique: true},
description: {type: 'string', maxlength: 2000, nullable: true},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
roles_users: {
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
role_id: {type: 'string', maxlength: 24, nullable: false},
user_id: {type: 'string', maxlength: 24, nullable: false}
},
permissions: {
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
name: {type: 'string', maxlength: 50, nullable: false, unique: true},
object_type: {type: 'string', maxlength: 50, nullable: false},
action_type: {type: 'string', maxlength: 50, nullable: false},
object_id: {type: 'string', maxlength: 24, nullable: true},
created_at: {type: 'dateTime', nullable: false},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
permissions_users: {
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
user_id: {type: 'string', maxlength: 24, nullable: false},
permission_id: {type: 'string', maxlength: 24, nullable: false}
},
permissions_roles: {
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
role_id: {type: 'string', maxlength: 24, nullable: false},
permission_id: {type: 'string', maxlength: 24, nullable: false}
},
settings: {
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
group: {
type: 'string',
maxlength: 50,
nullable: false,
defaultTo: 'core',
validations: {
isIn: [[
'amp',
'core',
'email',
'labs',
'members',
'portal',
'private',
'site',
'slack',
'theme',
'unsplash',
'views'
]]
}
},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
key: {type: 'string', maxlength: 50, nullable: false, unique: true},
2021-03-04 01:27:31 +03:00
// NOTE: as JSON objects are no longer stored in `value` we could potentially reduce the maxlength
value: {type: 'text', maxlength: 65535, nullable: true},
✨ Multiple authors (#9426) no issue This PR adds the server side logic for multiple authors. This adds the ability to add multiple authors per post. We keep and support single authors (maybe till the next major - this is still in discussion) ### key notes - `authors` are not fetched by default, only if we need them - the migration script iterates over all posts and figures out if an author_id is valid and exists (in master we can add invalid author_id's) and then adds the relation (falls back to owner if invalid) - ~~i had to push a fork of bookshelf to npm because we currently can't bump bookshelf + the two bugs i discovered are anyway not yet merged (https://github.com/kirrg001/bookshelf/commits/master)~~ replaced by new bookshelf release - the implementation of single & multiple authors lives in a single place (introduction of a new concept: model relation) - if you destroy an author, we keep the behaviour for now -> remove all posts where the primary author id matches. furthermore, remove all relations in posts_authors (e.g. secondary author) - we make re-use of the `excludeAttrs` concept which was invented in the contributors PR (to protect editing authors as author/contributor role) -> i've added a clear todo that we need a logic to make a diff of the target relation -> both for tags and authors - `authors` helper available (same as `tags` helper) - `primary_author` computed field available - `primary_author` functionality available (same as `primary_tag` e.g. permalinks, prev/next helper etc)
2018-03-27 17:16:15 +03:00
type: {
type: 'string',
maxlength: 50,
nullable: false,
validations: {
isIn: [[
'array',
'string',
'number',
'boolean',
'object'
]]
}
✨ Multiple authors (#9426) no issue This PR adds the server side logic for multiple authors. This adds the ability to add multiple authors per post. We keep and support single authors (maybe till the next major - this is still in discussion) ### key notes - `authors` are not fetched by default, only if we need them - the migration script iterates over all posts and figures out if an author_id is valid and exists (in master we can add invalid author_id's) and then adds the relation (falls back to owner if invalid) - ~~i had to push a fork of bookshelf to npm because we currently can't bump bookshelf + the two bugs i discovered are anyway not yet merged (https://github.com/kirrg001/bookshelf/commits/master)~~ replaced by new bookshelf release - the implementation of single & multiple authors lives in a single place (introduction of a new concept: model relation) - if you destroy an author, we keep the behaviour for now -> remove all posts where the primary author id matches. furthermore, remove all relations in posts_authors (e.g. secondary author) - we make re-use of the `excludeAttrs` concept which was invented in the contributors PR (to protect editing authors as author/contributor role) -> i've added a clear todo that we need a logic to make a diff of the target relation -> both for tags and authors - `authors` helper available (same as `tags` helper) - `primary_author` computed field available - `primary_author` functionality available (same as `primary_tag` e.g. permalinks, prev/next helper etc)
2018-03-27 17:16:15 +03:00
},
flags: {type: 'string', maxlength: 50, nullable: true},
created_at: {type: 'dateTime', nullable: false},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
tags: {
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
name: {type: 'string', maxlength: 191, nullable: false, validations: {matches: /^([^,]|$)/}},
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
description: {type: 'text', maxlength: 65535, nullable: true, validations: {isLength: {max: 500}}},
feature_image: {type: 'string', maxlength: 2000, nullable: true},
✨ replace auto increment id's by object id (#7495) * 🛠 bookshelf tarball, bson-objectid * 🎨 schema changes - change increment type to string - add a default fallback for string length 191 (to avoid adding this logic to every single column which uses an ID) - remove uuid, because ID now represents a global resource identifier - keep uuid for post, because we are using this as preview id - keep uuid for clients for now - we are using this param for Ghost-Auth * ✨ base model: generate ObjectId on creating event - each new resource get's a auto generate ObjectId - this logic won't work for attached models, this commit comes later * 🎨 centralised attach method When attaching models there are two things important two know 1. To be able to attach an ObjectId, we need to register the `onCreating` event the fetched model!This is caused by the Bookshelf design in general. On this target model we are attaching the new model. 2. We need to manually fetch the target model, because Bookshelf has a weird behaviour (which is known as a bug, see see https://github.com/tgriesser/bookshelf/issues/629). The most important property when attaching a model is `parentFk`, which is the foreign key. This can be null when fetching the model with the option `withRelated`. To ensure quality and consistency, the custom attach wrapper always fetches the target model manual. By fetching the target model (again) is a little performance decrease, but it also has advantages: we can register the event, and directly unregister the event again. So very clean code. Important: please only use the custom attach wrapper in the future. * 🎨 token model had overriden the onCreating function because of the created_at field - we need to ensure that the base onCreating hook get's triggered for ALL models - if not, they don't get an ObjectId assigned - in this case: be smart and check if the target model has a created_at field * 🎨 we don't have a uuid field anymore, remove the usages - no default uuid creation in models - i am pretty sure we have some more definitions in our tests (for example in the export json files), but that is too much work to delete them all * 🎨 do not parse ID to Number - we had various occurances of parsing all ID's to numbers - we don't need this behaviour anymore - ID is string - i will adapt the ID validation in the next commit * 🎨 change ID regex for validation - we only allow: ID as ObjectId, ID as 1 and ID as me - we need to keep ID 1, because our whole software relies on ID 1 (permissions etc) * 🎨 owner fixture - roles: [4] does not work anymore - 4 means -> static id 4 - this worked in an auto increment system (not even in a system with distributed writes) - with ObjectId we generate each ID automatically (for static and dynamic resources) - it is possible to define all id's for static resources still, but that means we need to know which ID is already used and for consistency we have to define ObjectId's for these static resources - so no static id's anymore, except of: id 1 for owner and id 0 for external usage (because this is required from our permission system) - NOTE: please read through the comment in the user model * 🎨 tests: DataGenerator and test utils First of all: we need to ensure using ObjectId's in the tests. When don't, we can't ensure that ObjectId's work properly. This commit brings lot's of dynamic into all the static defined id's. In one of the next commits, i will adapt all the tests. * 🚨 remove counter in Notification API - no need to add a counter - we simply generate ObjectId's (they are auto incremental as well) - our id validator does only allow ObjectId as id,1 and me * 🎨 extend contextUser in Base Model - remove isNumber check, because id's are no longer numbers, except of id 0/1 - use existing isExternalUser - support id 0/1 as string or number * ✨ Ghost Owner has id 1 - ensure we define this id in the fixtures.json - doesn't matter if number or string * 🎨 functional tests adaptions - use dynamic id's * 🎨 fix unit tests * 🎨 integration tests adaptions * 🎨 change importer utils - all our export examples (test/fixtures/exports) contain id's as numbers - fact: but we ignore them anyway when inserting into the database, see https://github.com/TryGhost/Ghost/blob/master/core/server/data/import/utils.js#L249 - in https://github.com/TryGhost/Ghost/pull/7495/commits/0e6ed957cd54dc02a25cf6fb1ab7d7e723295e2c#diff-70f514a06347c048648be464819503c4L67 i removed parsing id's to integers - i realised that this ^ check just existed, because the userIdToMap was an object key and object keys are always strings! - i think this logic is a little bit complicated, but i don't want to refactor this now - this commit ensures when trying to find the user, the id comparison works again - i've added more documentation to understand this logic ;) - plus i renamed an attribute to improve readability * 🎨 Data-Generator: add more defaults to createUser - if i use the function DataGenerator.forKnex.createUser i would like to get a full set of defaults * 🎨 test utils: change/extend function set for functional tests - functional tests work a bit different - they boot Ghost and seed the database - some functional tests have mis-used the test setup - the test setup needs two sections: integration/unit and functional tests - any functional test is allowed to either add more data or change data in the existing Ghost db - but what it should not do is: add test fixtures like roles or users from our DataGenerator and cross fingers it will work - this commit adds a clean method for functional tests to add extra users * 🎨 functional tests adaptions - use last commit to insert users for functional tests clean - tidy up usage of testUtils.setup or testUtils.doAuth * 🐛 test utils: reset database before init - ensure we don't have any left data from other tests in the database when starting ghost * 🐛 fix test (unrelated to this PR) - fixes a random failure - return statement was missing * 🎨 make changes for invites
2016-11-17 12:09:11 +03:00
parent_id: {type: 'string', nullable: true},
✨ Multiple authors (#9426) no issue This PR adds the server side logic for multiple authors. This adds the ability to add multiple authors per post. We keep and support single authors (maybe till the next major - this is still in discussion) ### key notes - `authors` are not fetched by default, only if we need them - the migration script iterates over all posts and figures out if an author_id is valid and exists (in master we can add invalid author_id's) and then adds the relation (falls back to owner if invalid) - ~~i had to push a fork of bookshelf to npm because we currently can't bump bookshelf + the two bugs i discovered are anyway not yet merged (https://github.com/kirrg001/bookshelf/commits/master)~~ replaced by new bookshelf release - the implementation of single & multiple authors lives in a single place (introduction of a new concept: model relation) - if you destroy an author, we keep the behaviour for now -> remove all posts where the primary author id matches. furthermore, remove all relations in posts_authors (e.g. secondary author) - we make re-use of the `excludeAttrs` concept which was invented in the contributors PR (to protect editing authors as author/contributor role) -> i've added a clear todo that we need a logic to make a diff of the target relation -> both for tags and authors - `authors` helper available (same as `tags` helper) - `primary_author` computed field available - `primary_author` functionality available (same as `primary_tag` e.g. permalinks, prev/next helper etc)
2018-03-27 17:16:15 +03:00
visibility: {
type: 'string',
maxlength: 50,
nullable: false,
defaultTo: 'public',
validations: {isIn: [['public', 'internal']]}
},
og_image: {type: 'string', maxlength: 2000, nullable: true},
og_title: {type: 'string', maxlength: 300, nullable: true},
og_description: {type: 'string', maxlength: 500, nullable: true},
twitter_image: {type: 'string', maxlength: 2000, nullable: true},
twitter_title: {type: 'string', maxlength: 300, nullable: true},
twitter_description: {type: 'string', maxlength: 500, nullable: true},
meta_title: {type: 'string', maxlength: 2000, nullable: true, validations: {isLength: {max: 300}}},
meta_description: {type: 'string', maxlength: 2000, nullable: true, validations: {isLength: {max: 500}}},
codeinjection_head: {type: 'text', maxlength: 65535, nullable: true},
codeinjection_foot: {type: 'text', maxlength: 65535, nullable: true},
canonical_url: {type: 'string', maxlength: 2000, nullable: true},
accent_color: {type: 'string', maxlength: 50, nullable: true},
created_at: {type: 'dateTime', nullable: false},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
posts_tags: {
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
post_id: {type: 'string', maxlength: 24, nullable: false, references: 'posts.id'},
tag_id: {type: 'string', maxlength: 24, nullable: false, references: 'tags.id'},
✨ replace auto increment id's by object id (#7495) * 🛠 bookshelf tarball, bson-objectid * 🎨 schema changes - change increment type to string - add a default fallback for string length 191 (to avoid adding this logic to every single column which uses an ID) - remove uuid, because ID now represents a global resource identifier - keep uuid for post, because we are using this as preview id - keep uuid for clients for now - we are using this param for Ghost-Auth * ✨ base model: generate ObjectId on creating event - each new resource get's a auto generate ObjectId - this logic won't work for attached models, this commit comes later * 🎨 centralised attach method When attaching models there are two things important two know 1. To be able to attach an ObjectId, we need to register the `onCreating` event the fetched model!This is caused by the Bookshelf design in general. On this target model we are attaching the new model. 2. We need to manually fetch the target model, because Bookshelf has a weird behaviour (which is known as a bug, see see https://github.com/tgriesser/bookshelf/issues/629). The most important property when attaching a model is `parentFk`, which is the foreign key. This can be null when fetching the model with the option `withRelated`. To ensure quality and consistency, the custom attach wrapper always fetches the target model manual. By fetching the target model (again) is a little performance decrease, but it also has advantages: we can register the event, and directly unregister the event again. So very clean code. Important: please only use the custom attach wrapper in the future. * 🎨 token model had overriden the onCreating function because of the created_at field - we need to ensure that the base onCreating hook get's triggered for ALL models - if not, they don't get an ObjectId assigned - in this case: be smart and check if the target model has a created_at field * 🎨 we don't have a uuid field anymore, remove the usages - no default uuid creation in models - i am pretty sure we have some more definitions in our tests (for example in the export json files), but that is too much work to delete them all * 🎨 do not parse ID to Number - we had various occurances of parsing all ID's to numbers - we don't need this behaviour anymore - ID is string - i will adapt the ID validation in the next commit * 🎨 change ID regex for validation - we only allow: ID as ObjectId, ID as 1 and ID as me - we need to keep ID 1, because our whole software relies on ID 1 (permissions etc) * 🎨 owner fixture - roles: [4] does not work anymore - 4 means -> static id 4 - this worked in an auto increment system (not even in a system with distributed writes) - with ObjectId we generate each ID automatically (for static and dynamic resources) - it is possible to define all id's for static resources still, but that means we need to know which ID is already used and for consistency we have to define ObjectId's for these static resources - so no static id's anymore, except of: id 1 for owner and id 0 for external usage (because this is required from our permission system) - NOTE: please read through the comment in the user model * 🎨 tests: DataGenerator and test utils First of all: we need to ensure using ObjectId's in the tests. When don't, we can't ensure that ObjectId's work properly. This commit brings lot's of dynamic into all the static defined id's. In one of the next commits, i will adapt all the tests. * 🚨 remove counter in Notification API - no need to add a counter - we simply generate ObjectId's (they are auto incremental as well) - our id validator does only allow ObjectId as id,1 and me * 🎨 extend contextUser in Base Model - remove isNumber check, because id's are no longer numbers, except of id 0/1 - use existing isExternalUser - support id 0/1 as string or number * ✨ Ghost Owner has id 1 - ensure we define this id in the fixtures.json - doesn't matter if number or string * 🎨 functional tests adaptions - use dynamic id's * 🎨 fix unit tests * 🎨 integration tests adaptions * 🎨 change importer utils - all our export examples (test/fixtures/exports) contain id's as numbers - fact: but we ignore them anyway when inserting into the database, see https://github.com/TryGhost/Ghost/blob/master/core/server/data/import/utils.js#L249 - in https://github.com/TryGhost/Ghost/pull/7495/commits/0e6ed957cd54dc02a25cf6fb1ab7d7e723295e2c#diff-70f514a06347c048648be464819503c4L67 i removed parsing id's to integers - i realised that this ^ check just existed, because the userIdToMap was an object key and object keys are always strings! - i think this logic is a little bit complicated, but i don't want to refactor this now - this commit ensures when trying to find the user, the id comparison works again - i've added more documentation to understand this logic ;) - plus i renamed an attribute to improve readability * 🎨 Data-Generator: add more defaults to createUser - if i use the function DataGenerator.forKnex.createUser i would like to get a full set of defaults * 🎨 test utils: change/extend function set for functional tests - functional tests work a bit different - they boot Ghost and seed the database - some functional tests have mis-used the test setup - the test setup needs two sections: integration/unit and functional tests - any functional test is allowed to either add more data or change data in the existing Ghost db - but what it should not do is: add test fixtures like roles or users from our DataGenerator and cross fingers it will work - this commit adds a clean method for functional tests to add extra users * 🎨 functional tests adaptions - use last commit to insert users for functional tests clean - tidy up usage of testUtils.setup or testUtils.doAuth * 🐛 test utils: reset database before init - ensure we don't have any left data from other tests in the database when starting ghost * 🐛 fix test (unrelated to this PR) - fixes a random failure - return statement was missing * 🎨 make changes for invites
2016-11-17 12:09:11 +03:00
sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0}
},
invites: {
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
role_id: {type: 'string', maxlength: 24, nullable: false},
✨ Multiple authors (#9426) no issue This PR adds the server side logic for multiple authors. This adds the ability to add multiple authors per post. We keep and support single authors (maybe till the next major - this is still in discussion) ### key notes - `authors` are not fetched by default, only if we need them - the migration script iterates over all posts and figures out if an author_id is valid and exists (in master we can add invalid author_id's) and then adds the relation (falls back to owner if invalid) - ~~i had to push a fork of bookshelf to npm because we currently can't bump bookshelf + the two bugs i discovered are anyway not yet merged (https://github.com/kirrg001/bookshelf/commits/master)~~ replaced by new bookshelf release - the implementation of single & multiple authors lives in a single place (introduction of a new concept: model relation) - if you destroy an author, we keep the behaviour for now -> remove all posts where the primary author id matches. furthermore, remove all relations in posts_authors (e.g. secondary author) - we make re-use of the `excludeAttrs` concept which was invented in the contributors PR (to protect editing authors as author/contributor role) -> i've added a clear todo that we need a logic to make a diff of the target relation -> both for tags and authors - `authors` helper available (same as `tags` helper) - `primary_author` computed field available - `primary_author` functionality available (same as `primary_tag` e.g. permalinks, prev/next helper etc)
2018-03-27 17:16:15 +03:00
status: {
type: 'string',
maxlength: 50,
nullable: false,
defaultTo: 'pending',
validations: {isIn: [['pending', 'sent']]}
},
token: {type: 'string', maxlength: 191, nullable: false, unique: true},
email: {type: 'string', maxlength: 191, nullable: false, unique: true, validations: {isEmail: true}},
expires: {type: 'bigInteger', nullable: false},
created_at: {type: 'dateTime', nullable: false},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
🚨 database: change hard limits and field types (#7932) refs #7432 🚨 database: change hard limits and field types - we went over all schema fields and decided to decrease/increase the hard limits - the core goal is to have more flexibility in the future - we reconsidered string vs. text There are 5 groups: - small strings: 50 characters - static strings - status, visibility, language, role name, permission name, client name etc. - medium strings: 191 characters - all unique fields or fields which can be unique in the future - slug, tokens, user name, password, tag name, email - large strings: 1000-2000 characters - these fields need to be very flexible - these fields get a soft limit attached (in a different PR) - post title, meta title, meta description, urls - medium text: 64kb characters - bio, settings, location, tour - long text: 1000000000 chars - html, amp, mobiledoc, markdown 🙄 sort_order for tests - sort order was not set for the tests, so it was always 0 - mysql could return a different result in my case: - field length 156 returned the following related tags ["bacon", "kitchen"] - field length 157 returned the following related tags ["kitchen", "kitchen"] Change client.secret to 191 Tweak field lengths - Add 24 char limit for ids - Limited fields are the exact length they need - Unified 1000 and 2000 char string classes to all be 2000 - Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?! - Updated tests 🛠 Update importer tests - The old 001-003 tests are kind of less relevant now. - Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data - I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions 🔥 Remove foreign key from subscribers.post_id - There's no real need to have an index on this column, it just makes deleting posts hard. - Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-18 01:20:59 +03:00
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
brute: {
key: {type: 'string', maxlength: 191, primary: true},
firstRequest: {type: 'bigInteger'},
lastRequest: {type: 'bigInteger'},
lifetime: {type: 'bigInteger'},
count: {type: 'integer'}
},
sessions: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
session_id: {type: 'string', maxlength: 32, nullable: false, unique: true},
user_id: {type: 'string', maxlength: 24, nullable: false},
session_data: {type: 'string', maxlength: 2000, nullable: false},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
},
integrations: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
type: {
type: 'string',
maxlength: 50,
nullable: false,
defaultTo: 'custom',
validations: {isIn: [['internal', 'builtin', 'custom']]}
},
name: {type: 'string', maxlength: 191, nullable: false},
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
icon_image: {type: 'string', maxlength: 2000, nullable: true},
description: {type: 'string', maxlength: 2000, nullable: true},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
webhooks: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
event: {type: 'string', maxlength: 50, nullable: false, validations: {isLowercase: true}},
target_url: {type: 'string', maxlength: 2000, nullable: false},
name: {type: 'string', maxlength: 191, nullable: true},
secret: {type: 'string', maxlength: 191, nullable: true},
// NOTE: the defaultTo does not make sense to set on DB layer as it leads to unnecessary maintenance every major release
// it might make sense to introduce "isIn" validation checking if it's a valid version e.g: 'v3', 'v4', 'canary'
api_version: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'v2'},
// NOTE: integration_id column needs "nullable: true" -> "nullable: false" migration (recreate table with nullable: false)
// CASE: Ghost instances initialized pre 4.0 will have this column set to nullable: true in db schema
integration_id: {type: 'string', maxlength: 24, nullable: false, references: 'integrations.id', cascadeDelete: true},
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'available'},
last_triggered_at: {type: 'dateTime', nullable: true},
last_triggered_status: {type: 'string', maxlength: 50, nullable: true},
last_triggered_error: {type: 'string', maxlength: 50, nullable: true},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
api_keys: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
type: {
type: 'string',
maxlength: 50,
nullable: false,
validations: {isIn: [['content', 'admin']]}
},
secret: {
type: 'string',
maxlength: 191,
nullable: false,
unique: true,
validations: {isLength: {min: 26, max: 128}}
},
role_id: {type: 'string', maxlength: 24, nullable: true},
// integration_id is nullable to allow "internal" API keys that don't show in the UI
integration_id: {type: 'string', maxlength: 24, nullable: true},
user_id: {type: 'string', maxlength: 24, nullable: true},
last_seen_at: {type: 'dateTime', nullable: true},
last_seen_version: {type: 'string', maxlength: 50, nullable: true},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
mobiledoc_revisions: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
post_id: {type: 'string', maxlength: 24, nullable: false, index: true},
mobiledoc: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
created_at_ts: {type: 'bigInteger', nullable: false},
created_at: {type: 'dateTime', nullable: false}
},
members: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
uuid: {type: 'string', maxlength: 36, nullable: true, unique: true, validations: {isUUID: true}},
email: {type: 'string', maxlength: 191, nullable: false, unique: true, validations: {isEmail: true}},
status: {
type: 'string', maxlength: 50, nullable: false, defaultTo: 'free', validations: {
isIn: [['free', 'paid', 'comped']]
}
},
name: {type: 'string', maxlength: 191, nullable: true},
note: {type: 'string', maxlength: 2000, nullable: true},
geolocation: {type: 'string', maxlength: 2000, nullable: true},
subscribed: {type: 'bool', nullable: true, defaultTo: true},
email_count: {type: 'integer', unsigned: true, nullable: false, defaultTo: 0},
email_opened_count: {type: 'integer', unsigned: true, nullable: false, defaultTo: 0},
email_open_rate: {type: 'integer', unsigned: true, nullable: true, index: true},
last_seen_at: {type: 'dateTime',nullable: true},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
products: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
name: {type: 'string', maxlength: 191, nullable: false},
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
active: {type: 'boolean', nullable: false, defaultTo: true},
welcome_page_url: {type: 'string', maxlength: 2000, nullable: true},
visibility: {
type: 'string',
maxlength: 50,
nullable: false,
defaultTo: 'none',
validations: {isIn: [['public', 'none']]}
},
monthly_price_id: {type: 'string', maxlength: 24, nullable: true},
yearly_price_id: {type: 'string', maxlength: 24, nullable: true},
description: {type: 'string', maxlength: 191, nullable: true},
type: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'paid', validations: {isIn: [['paid', 'free']]}},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
},
offers: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
active: {type: 'boolean', nullable: false, defaultTo: true},
name: {type: 'string', maxlength: 191, nullable: false, unique: true},
code: {type: 'string', maxlength: 191, nullable: false, unique: true},
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id'},
stripe_coupon_id: {type: 'string', maxlength: 255, nullable: true, unique: true},
interval: {type: 'string', maxlength: 50, nullable: false, validations: {isIn: [['month', 'year']]}},
currency: {type: 'string', maxlength: 50, nullable: true},
discount_type: {type: 'string', maxlength: 50, nullable: false, validations: {isIn: [['percent', 'amount']]}},
discount_amount: {type: 'integer', nullable: false},
duration: {type: 'string', maxlength: 50, nullable: false},
duration_in_months: {type: 'integer', nullable: true},
portal_title: {type: 'string', maxlength: 191, nullable: true},
portal_description: {type: 'string', maxlength: 2000, nullable: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
},
benefits: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
name: {type: 'string', maxlength: 191, nullable: false},
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
},
products_benefits: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id', cascadeDelete: true},
benefit_id: {type: 'string', maxlength: 24, nullable: false, references: 'benefits.id', cascadeDelete: true},
sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0}
},
members_products: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id', cascadeDelete: true},
sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0}
},
posts_products: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
post_id: {type: 'string', maxlength: 24, nullable: false, references: 'posts.id', cascadeDelete: true},
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id', cascadeDelete: true},
sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0}
},
members_cancel_events: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
from_plan: {type: 'string', maxlength: 255, nullable: false},
created_at: {type: 'dateTime', nullable: false}
},
members_payment_events: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
amount: {type: 'integer', nullable: false},
currency: {type: 'string', maxLength: 3, nullable: false},
source: {type: 'string', maxlength: 50, nullable: false},
created_at: {type: 'dateTime', nullable: false}
},
members_login_events: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
created_at: {type: 'dateTime', nullable: false}
},
members_email_change_events: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
to_email: {type: 'string', maxlength: 191, nullable: false, unique: false, validations: {isEmail: true}},
from_email: {type: 'string', maxlength: 191, nullable: false, unique: false, validations: {isEmail: true}},
created_at: {type: 'dateTime', nullable: false}
},
members_status_events: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
from_status: {
type: 'string', maxlength: 50, nullable: true, validations: {
isIn: [['free', 'paid', 'comped']]
}
},
to_status: {
type: 'string', maxlength: 50, nullable: true, validations: {
isIn: [['free', 'paid', 'comped']]
}
},
created_at: {type: 'dateTime', nullable: false}
},
members_product_events: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id', cascadeDelete: false},
action: {
type: 'string', maxlength: 50, nullable: true, validations: {
isIn: [['added', 'removed']]
}
},
created_at: {type: 'dateTime', nullable: false}
},
members_paid_subscription_events: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
from_plan: {type: 'string', maxlength: 255, nullable: true},
to_plan: {type: 'string', maxlength: 255, nullable: true},
currency: {type: 'string', maxLength: 3, nullable: false},
source: {
type: 'string', maxlength: 50, nullable: false, validations: {
isIn: [['stripe']]
}
},
mrr_delta: {type: 'integer', nullable: false},
created_at: {type: 'dateTime', nullable: false}
},
labels: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
name: {type: 'string', maxlength: 191, nullable: false, unique: true},
slug: {type: 'string', maxlength: 191, nullable: false, unique: true},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
members_labels: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
label_id: {type: 'string', maxlength: 24, nullable: false, references: 'labels.id', cascadeDelete: true},
sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0}
},
members_stripe_customers: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'members.id', cascadeDelete: true},
customer_id: {type: 'string', maxlength: 255, nullable: false, unique: true},
name: {type: 'string', maxlength: 191, nullable: true},
email: {type: 'string', maxlength: 191, nullable: true},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
members_stripe_customers_subscriptions: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
customer_id: {type: 'string', maxlength: 255, nullable: false, unique: false, references: 'members_stripe_customers.customer_id', cascadeDelete: true},
subscription_id: {type: 'string', maxlength: 255, nullable: false, unique: true},
stripe_price_id: {type: 'string', maxlength: 255, nullable: false, unique: false, index: true, defaultTo: ''},
status: {type: 'string', maxlength: 50, nullable: false},
cancel_at_period_end: {type: 'bool', nullable: false, defaultTo: false},
cancellation_reason: {type: 'string', maxlength: 500, nullable: true},
current_period_end: {type: 'dateTime', nullable: false},
start_date: {type: 'dateTime', nullable: false},
default_payment_card_last4: {type: 'string', maxlength: 4, nullable: true},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true},
/* Below fields are now redundant as we link prie_id to stripe_prices table */
plan_id: {type: 'string', maxlength: 255, nullable: false, unique: false},
plan_nickname: {type: 'string', maxlength: 50, nullable: false},
plan_interval: {type: 'string', maxlength: 50, nullable: false},
plan_amount: {type: 'integer', nullable: false},
plan_currency: {type: 'string', maxLength: 3, nullable: false}
},
offer_redemptions: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
offer_id: {type: 'string', maxlength: 24, nullable: false, references: 'offers.id', cascadeDelete: true},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
subscription_id: {type: 'string', maxlength: 24, nullable: false, references: 'members_stripe_customers_subscriptions.id', cascadeDelete: true},
created_at: {type: 'dateTime', nullable: false}
},
members_subscribe_events: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
member_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'members.id', cascadeDelete: true},
subscribed: {type: 'bool', nullable: false, defaultTo: true},
created_at: {type: 'dateTime', nullable: false},
source: {type: 'string', maxlength: 50, nullable: true}
},
stripe_products: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
product_id: {type: 'string', maxlength: 24, nullable: false, unique: false, references: 'products.id'},
stripe_product_id: {type: 'string', maxlength: 255, nullable: false, unique: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
},
stripe_prices: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
stripe_price_id: {type: 'string', maxlength: 255, nullable: false, unique: true},
stripe_product_id: {type: 'string', maxlength: 255, nullable: false, unique: false, references: 'stripe_products.stripe_product_id'},
active: {type: 'bool', nullable: false},
nickname: {type: 'string', maxlength: 50, nullable: true},
currency: {type: 'string', maxLength: 3, nullable: false},
amount: {type: 'integer', nullable: false},
type: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'recurring', validations: {isIn: [['recurring', 'one_time']]}},
interval: {type: 'string', maxlength: 50, nullable: true},
description: {type: 'string', maxlength: 191, nullable: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
},
actions: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
resource_id: {type: 'string', maxlength: 24, nullable: true},
resource_type: {type: 'string', maxlength: 50, nullable: false},
actor_id: {type: 'string', maxlength: 24, nullable: false},
actor_type: {type: 'string', maxlength: 50, nullable: false},
// @NOTE: The event column contains short buzzwords e.g. subscribed, started, added, deleted, edited etc.
// We already store and require the target resource type. No need to remember e.g. post.edited
event: {type: 'string', maxlength: 50, nullable: false},
// @NOTE: The context object can be used to store information about an action e.g. diffs, meta
context: {type: 'text', maxlength: 1000000000, nullable: true},
created_at: {type: 'dateTime', nullable: false}
2019-11-06 07:29:21 +03:00
},
emails: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
post_id: {type: 'string', maxlength: 24, nullable: false, index: true, unique: true},
2019-11-06 07:29:21 +03:00
uuid: {type: 'string', maxlength: 36, nullable: false, validations: {isUUID: true}},
status: {
type: 'string',
maxlength: 50,
nullable: false,
defaultTo: 'pending',
validations: {isIn: [['pending', 'submitting', 'submitted', 'failed']]}
2019-11-06 07:29:21 +03:00
},
recipient_filter: {
type: 'text',
maxlength: 1000000000,
nullable: false,
✨ Added ability to send a newsletter to members with a certain label or product (#12932) refs https://github.com/TryGhost/Team/issues/581 refs https://github.com/TryGhost/Team/issues/582 When publishing a post via the API it was possible to send it using `?email_recipient_filter=all/free/paid` which allowed you to send to members only based on their payment status which is quite limiting for some sites. This PR updates the `?email_recipient_filter` query param to support Ghost's `?filter` param syntax which enables more specific recipient lists, eg: `?email_recipient_filter=status:free` = free members only `?email_recipient_filter=status:paid` = paid members only `?email_recipient_filter=label:vip` = members that have the `vip` label attached `?email_recipient_filter=status:paid,label:vip` = paid members and members that have the `vip` label attached The older `free/paid` values are still supported by the API for backwards compatibility. - updates `Post` and `Email` models to transform legacy `free` and `paid` values to their NQL equivalents on read/write - lets us not worry about supporting legacy values elsewhere in the code - cleanup migration to transform all rows slated for 5.0 - removes schema and API `isIn` validations for recipient filters so allow free-form filters - updates posts API input serializers to transform `free` and `paid` values in the `?email_recipient_filter` param to their NQL equivalents for backwards compatibility - updates Post API controllers `edit` methods to run a query using the supplied filter to verify that it's valid - updates `mega` service to use the filter directly when selecting recipients
2021-05-07 13:56:41 +03:00
defaultTo: 'status:-free'
},
2019-11-06 07:29:21 +03:00
error: {type: 'string', maxlength: 2000, nullable: true},
error_data: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
2019-11-06 07:29:21 +03:00
email_count: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0},
delivered_count: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0},
opened_count: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0},
failed_count: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0},
2019-11-06 07:29:21 +03:00
subject: {type: 'string', maxlength: 300, nullable: true},
from: {type: 'string', maxlength: 2000, nullable: true},
reply_to: {type: 'string', maxlength: 2000, nullable: true},
2019-11-06 07:29:21 +03:00
html: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
plaintext: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
track_opens: {type: 'bool', nullable: false, defaultTo: false},
2019-11-06 07:29:21 +03:00
submitted_at: {type: 'dateTime', nullable: false},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
email_batches: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
email_id: {type: 'string', maxlength: 24, nullable: false, references: 'emails.id'},
provider_id: {type: 'string', maxlength: 255, nullable: true},
status: {
type: 'string',
maxlength: 50,
nullable: false,
defaultTo: 'pending',
validations: {isIn: [['pending', 'submitting', 'submitted', 'failed']]}
},
member_segment: {type: 'text', maxlength: 2000, nullable: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: false}
},
email_recipients: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
email_id: {type: 'string', maxlength: 24, nullable: false, references: 'emails.id'},
member_id: {type: 'string', maxlength: 24, nullable: false, index: true},
batch_id: {type: 'string', maxlength: 24, nullable: false, references: 'email_batches.id'},
processed_at: {type: 'dateTime', nullable: true},
delivered_at: {type: 'dateTime', nullable: true, index: true},
opened_at: {type: 'dateTime', nullable: true, index: true},
failed_at: {type: 'dateTime', nullable: true, index: true},
member_uuid: {type: 'string', maxlength: 36, nullable: false},
member_email: {type: 'string', maxlength: 191, nullable: false},
member_name: {type: 'string', maxlength: 191, nullable: true},
'@@INDEXES@@': [
['email_id', 'member_email']
]
},
tokens: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
token: {type: 'string', maxlength: 32, nullable: false, index: true},
data: {type: 'string', maxlength: 2000, nullable: true},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false}
},
snippets: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
name: {type: 'string', maxlength: 191, nullable: false, unique: true},
mobiledoc: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: false},
created_at: {type: 'dateTime', nullable: false},
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
temp_member_analytic_events: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
event_name: {type: 'string', maxlength: 50, nullable: false},
created_at: {type: 'dateTime', nullable: false},
member_id: {type: 'string', maxlength: 24, nullable: false},
member_status: {type: 'string', maxlength: 50, nullable: false},
entry_id: {type: 'string', maxlength: 24, nullable: true},
source_url: {type: 'string', maxlength: 2000, nullable: true},
metadata: {type: 'string', maxlength: 191, nullable: true}
},
custom_theme_settings: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
theme: {type: 'string', maxlength: 191, nullable: false},
key: {type: 'string', maxlength: 191, nullable: false},
type: {
type: 'string',
maxlength: 50,
nullable: false,
validations: {
isIn: [[
'select',
'boolean',
'color',
'text',
'image'
]]
}
},
value: {type: 'text', maxlength: 65535, nullable: true}
},
newsletters: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
name: {type: 'string', maxlength: 191, nullable: false},
description: {type: 'string', maxlength: 2000, nullable: true},
sender_name: {type: 'string', maxlength: 191, nullable: false},
sender_email: {type: 'string', maxlength: 191, nullable: false, validations: {isEmail: true}},
sender_reply_to: {type: 'string', maxlength: 191, nullable: false, validations: {isEmail: true}},
default: {type: 'bool', nullable: false, defaultTo: false},
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'active'},
recipient_filter: {
type: 'text',
maxlength: 1000000000,
nullable: false,
defaultTo: ''
},
subscribe_on_signup: {type: 'bool', nullable: false, defaultTo: false},
sort_order: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0}
}
};