Skip to content

Instantly share code, notes, and snippets.

@tiagoeborsanyi
Created June 7, 2016 21:29
Show Gist options
  • Save tiagoeborsanyi/d9816142d0abadc8931f63c449521f64 to your computer and use it in GitHub Desktop.
Save tiagoeborsanyi/d9816142d0abadc8931f63c449521f64 to your computer and use it in GitHub Desktop.
SCHEMA MONGOO:
var mongoose = require('mongoose');
module.exports = function () {
var schema = mongoose.Schema({
origin: {
type: String,
required: true
},
deatination: {
type: String,
required: true
},
waypoints: [],
travelmode: {
type: String,
required: true
},
videos: [],
fotos: [],
fotocapa: String,
comentarios: [],
curtidas: Number,
viagemnome: String,
usuario: {
type: mongoose.Schema.ObjectId,
ref: 'User'
},
data: {
type: Date,
default: Date
}
});
return mongoose.model('Rota', schema);
};
/* The user schema attributes - characteristics - fiels */
var UserSchema = new Schema({
email: {
type: String,
unique: true,
lowercase: true
},
password: String,
login: String,
profile: {
name: {
type: String,
default: ''
},
picture: {
type: String,
default: ''
}
},
address: String,
history: [{
date: Date,
paid: {type: Number, default: 0},
//item: {type: Schema.types.ObjectId, ref: ''}
}]
});
SCHEMA POSTGRE:
'use strict'
exports.up = (knex, Promise) => {
return knex.schema.createTable('users', (table) => {
table.uuid('id').primary()
table.string('email').unique().notNullable()
table.string('password').notNullable()
table.string('login').notNullable()
table.string('avatar')
table.timestamps()
}).createTable('planejamento', (table) => {
table.uuid('id').primary()
table.string('origin').notNullable()
table.string('destination').notNullable()
table.specificType('waypoints', 'json[]')
table.string('travelmode').notNullable()
table.string('fotocapa')
table.string('nomerota').notNullable()
table.uuid('author_id').notNullable().references('id').inTable('users')
table.timestamps()
}).createTable('comentarios', (table) => {
table.uuid('id').primary()
table.string('comments').notNullable()
table.integer('likes')
table.uuid('author_id').notNullable().references('id').inTable('users')
table.uuid('planejamento_id').notNullable().references('id').inTable('planejamento')
table.timestamps()
}).createTable('videos', (table) => {
table.uuid('id').primary()
table.string('localidade').notNullable()
table.string('urlvideo').notNullable()
table.uuid('author_id').notNullable().references('id').inTable('users')
table.uuid('planejamento_id').notNullable().references('id').inTable('planejamento')
table.timestamps()
}).createTable('fotos', (table) => {
table.uuid('id').primary()
table.string('localidade').notNullable()
table.string('urlvideo').notNullable()
table.uuid('author_id').notNullable().references('id').inTable('users')
table.uuid('planejamento_id').notNullable().references('id').inTable('planejamento')
table.timestamps()
})
};
exports.down = (knex, Promise) => {
return Promise.all([
knex.schema.dropTable('comentarios'),
knex.schema.dropTable('videos'),
knex.schema.dropTable('fotos'),
knex.schema.dropTable('planejamento'),
knex.schema.dropTable('users')
])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment