New database with migrations
This commit is contained in:
@@ -2,7 +2,7 @@ import {
|
||||
DataTypes,
|
||||
sequelize,
|
||||
} from '../sequelize';
|
||||
import Team from './Team';
|
||||
import Document from './Document';
|
||||
|
||||
const allowedAtlasTypes = [['atlas', 'journal']];
|
||||
|
||||
@@ -11,8 +11,33 @@ const Atlas = sequelize.define('atlas', {
|
||||
name: DataTypes.STRING,
|
||||
description: DataTypes.STRING,
|
||||
type: { type: DataTypes.STRING, validate: { isIn: allowedAtlasTypes }},
|
||||
|
||||
/* type: atlas */
|
||||
atlasStructure: DataTypes.JSONB,
|
||||
}, {
|
||||
tableName: 'atlases',
|
||||
hooks: {
|
||||
// beforeValidate: (doc) => {
|
||||
// doc.urlId = randomstring.generate(15);
|
||||
// },
|
||||
// beforeCreate: (doc) => {
|
||||
// doc.html = convertToMarkdown(doc.text);
|
||||
// doc.preview = truncateMarkdown(doc.text, 160);
|
||||
// },
|
||||
// beforeUpdate: (doc) => {
|
||||
// doc.html = convertToMarkdown(doc.text);
|
||||
// doc.preview = truncateMarkdown(doc.text, 160);
|
||||
// },
|
||||
},
|
||||
instanceMethods: {
|
||||
// buildUrl() {
|
||||
// const slugifiedTitle = slug(this.title);
|
||||
// return `${slugifiedTitle}-${this.urlId}`;
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
Atlas.belongsTo(Team);
|
||||
Atlas.hasMany(Document, { as: 'documents', foreignKey: 'atlasId' });
|
||||
Atlas.hasOne(Document, { as: 'rootDocument', foreignKey: 'rootDocumentForId', constraints: false });
|
||||
|
||||
export default Atlas;
|
||||
|
||||
@@ -10,8 +10,6 @@ import {
|
||||
import {
|
||||
truncateMarkdown,
|
||||
} from '../utils/truncate';
|
||||
import Atlas from './Atlas';
|
||||
import Team from './Team';
|
||||
import User from './User';
|
||||
|
||||
slug.defaults.mode ='rfc3986';
|
||||
@@ -51,8 +49,6 @@ const Document = sequelize.define('document', {
|
||||
}
|
||||
});
|
||||
|
||||
Document.belongsTo(Atlas, { as: 'atlas' });
|
||||
Document.belongsTo(Team);
|
||||
Document.belongsTo(User);
|
||||
|
||||
export default Document;
|
||||
|
||||
@@ -2,6 +2,9 @@ import {
|
||||
DataTypes,
|
||||
sequelize,
|
||||
} from '../sequelize';
|
||||
import Atlas from './Atlas';
|
||||
import Document from './Document';
|
||||
import User from './User';
|
||||
|
||||
const Team = sequelize.define('team', {
|
||||
id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true },
|
||||
@@ -9,6 +12,17 @@ const Team = sequelize.define('team', {
|
||||
slackId: { type: DataTypes.STRING, unique: true },
|
||||
slackData: DataTypes.JSONB,
|
||||
}, {
|
||||
instanceMethods: {
|
||||
async createFirstAtlas() {
|
||||
const atlas = await Atlas.create({
|
||||
name: this.name,
|
||||
description: 'Your first Atlas',
|
||||
type: 'journal',
|
||||
teamId: this.id,
|
||||
});
|
||||
return atlas;
|
||||
}
|
||||
},
|
||||
indexes: [
|
||||
{
|
||||
unique: true,
|
||||
@@ -17,4 +31,8 @@ const Team = sequelize.define('team', {
|
||||
],
|
||||
});
|
||||
|
||||
Team.hasMany(Atlas, { as: 'atlases' });
|
||||
Team.hasMany(Document, { as: 'documents' });
|
||||
Team.hasMany(User, { as: 'users' });
|
||||
|
||||
export default Team;
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
sequelize,
|
||||
encryptedFields
|
||||
} from '../sequelize';
|
||||
import Team from './Team';
|
||||
|
||||
import JWT from 'jsonwebtoken';
|
||||
|
||||
@@ -39,8 +38,5 @@ const setRandomJwtSecret = (model) => {
|
||||
};
|
||||
|
||||
User.beforeCreate(setRandomJwtSecret);
|
||||
User.belongsTo(Team);
|
||||
|
||||
sequelize.sync();
|
||||
|
||||
export default User;
|
||||
|
||||
Reference in New Issue
Block a user