Migrate all the things
* Migrates from Mongo to Postgres. * Migrates from JSPM to Webpack. * Migrates from React to Vuejs. * Migrates from Bootstrap to Bulma. Also: * Fixes rendering of meta data in the document head tag.
This commit is contained in:
parent
09706778d9
commit
7bb0497ff4
76 changed files with 6741 additions and 1760 deletions
36
models/album.js
Normal file
36
models/album.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
export default function (sequelize, DataTypes) {
|
||||
const Album = sequelize.define('album', {
|
||||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||
externalId: { type: DataTypes.STRING(50), index: true }, // eslint-disable-line new-cap
|
||||
service: DataTypes.ENUM( // eslint-disable-line new-cap
|
||||
'deezer',
|
||||
'google',
|
||||
'itunes',
|
||||
'spotify',
|
||||
'xbox',
|
||||
'youtube'
|
||||
),
|
||||
name: DataTypes.TEXT,
|
||||
artistId: DataTypes.INTEGER,
|
||||
}, {
|
||||
paranoid: true,
|
||||
classMethods: {
|
||||
associate: (models) => {
|
||||
Album.hasMany(models.match);
|
||||
Album.belongsTo(models.artist);
|
||||
},
|
||||
},
|
||||
indexes: [
|
||||
{
|
||||
fields: ['externalId', 'service'],
|
||||
},
|
||||
],
|
||||
getterMethods: {
|
||||
type() {
|
||||
return this.getDataValue('trackId') ? 'track' : 'album';
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return Album;
|
||||
}
|
25
models/artist.js
Normal file
25
models/artist.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
export default function (sequelize, DataTypes) {
|
||||
const Artist = sequelize.define('artist', {
|
||||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||
name: DataTypes.TEXT,
|
||||
streamUrl: DataTypes.TEXT,
|
||||
purchaseUrl: DataTypes.TEXT,
|
||||
artworkSmall: DataTypes.TEXT,
|
||||
artworkLarge: DataTypes.TEXT,
|
||||
}, {
|
||||
paranoid: true,
|
||||
classMethods: {
|
||||
associate: (models) => {
|
||||
Artist.hasMany(models.track);
|
||||
Artist.hasMany(models.album);
|
||||
},
|
||||
},
|
||||
indexes: [
|
||||
{
|
||||
fields: ['name'],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return Artist;
|
||||
}
|
35
models/index.js
Normal file
35
models/index.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import Sequelize from 'sequelize';
|
||||
|
||||
import debugname from 'debug';
|
||||
|
||||
const debug = debugname('match.audio:models');
|
||||
|
||||
const config = {
|
||||
dialect: 'postgres',
|
||||
protocol: 'postgres',
|
||||
logging: debug,
|
||||
};
|
||||
|
||||
const sequelize = new Sequelize(process.env.DATABASE_URL, config);
|
||||
const db = {};
|
||||
|
||||
fs
|
||||
.readdirSync(__dirname)
|
||||
.filter(file => (file.indexOf('.') !== 0) && (file !== 'index.js'))
|
||||
.forEach((file) => {
|
||||
const model = sequelize.import(path.join(__dirname, file));
|
||||
db[model.name] = model;
|
||||
});
|
||||
|
||||
Object.keys(db).forEach((modelName) => {
|
||||
if ('associate' in db[modelName]) {
|
||||
db[modelName].associate(db);
|
||||
}
|
||||
});
|
||||
|
||||
db.sequelize = sequelize;
|
||||
db.Sequelize = Sequelize;
|
||||
|
||||
export default db;
|
35
models/match.js
Normal file
35
models/match.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
export default function (sequelize, DataTypes) {
|
||||
const Match = sequelize.define('match', {
|
||||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||
trackId: DataTypes.INTEGER,
|
||||
albumId: DataTypes.INTEGER,
|
||||
externalId: { type: DataTypes.STRING(50), index: true }, // eslint-disable-line new-cap
|
||||
service: DataTypes.ENUM( // eslint-disable-line new-cap
|
||||
'deezer',
|
||||
'google',
|
||||
'itunes',
|
||||
'spotify',
|
||||
'xbox',
|
||||
'youtube'
|
||||
),
|
||||
name: DataTypes.TEXT,
|
||||
streamUrl: DataTypes.TEXT,
|
||||
purchaseUrl: DataTypes.TEXT,
|
||||
artworkSmall: DataTypes.TEXT,
|
||||
artworkLarge: DataTypes.TEXT,
|
||||
}, {
|
||||
paranoid: true,
|
||||
indexes: [
|
||||
{
|
||||
fields: ['externalId', 'service'],
|
||||
},
|
||||
],
|
||||
getterMethods: {
|
||||
type() {
|
||||
return this.getDataValue('trackId') ? 'track' : 'album';
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return Match;
|
||||
}
|
38
models/track.js
Normal file
38
models/track.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
export default function (sequelize, DataTypes) {
|
||||
const Track = sequelize.define('track', {
|
||||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
||||
externalId: { type: DataTypes.STRING(50), index: true }, // eslint-disable-line new-cap
|
||||
service: DataTypes.ENUM( // eslint-disable-line new-cap
|
||||
'deezer',
|
||||
'google',
|
||||
'itunes',
|
||||
'spotify',
|
||||
'xbox',
|
||||
'youtube'
|
||||
),
|
||||
name: DataTypes.TEXT,
|
||||
artistId: DataTypes.INTEGER,
|
||||
albumId: DataTypes.INTEGER,
|
||||
albumName: DataTypes.TEXT,
|
||||
}, {
|
||||
paranoid: true,
|
||||
classMethods: {
|
||||
associate: (models) => {
|
||||
Track.hasMany(models.match);
|
||||
Track.belongsTo(models.artist);
|
||||
},
|
||||
},
|
||||
indexes: [
|
||||
{
|
||||
fields: ['externalId', 'service'],
|
||||
},
|
||||
],
|
||||
getterMethods: {
|
||||
type() {
|
||||
return this.getDataValue('trackId') ? 'track' : 'album';
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return Track;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue