Users ObjectId migration

This commit is contained in:
vjrj 2017-12-22 16:35:57 +01:00
parent 4227389a67
commit fc56bd3273
7 changed files with 72 additions and 91 deletions

View file

@ -5,18 +5,11 @@ import SimpleSchema from 'simpl-schema';
import { defaultCreatedAt, defaultUpdateAt } from '/imports/api/Utility/Utils.js';
const schemaUserProfile = new SimpleSchema({
/* Our users has a name of type Object while Google Service, for instance, not */
/* Our users has a name of type Object while Google Service, for instance, String, so blackbox in true in profile */
/* name: { type: String, optional: true }, */
/* name: Object,
name: { type: Object, optional: true },
'name.first': String,
'name.last': String, */
lang: { type: String, optional: true },
telegramChatId: { type: Number, optional: true },
telegramUsername: { type: String, optional: true },
telegramFirstName: { type: String, optional: true },
telegramLanguageCode: { type: String, optional: true },
createdAt: defaultCreatedAt,
updatedAt: defaultUpdateAt
'name.last': String
});
const schemaUser = new SimpleSchema({
@ -59,11 +52,6 @@ const schemaUser = new SimpleSchema({
type: Boolean,
optional: true // if not present === notVerified
},
profile: {
type: schemaUserProfile,
// i18nLabel: 'Otros datos',
optional: true
},
// Make sure this services field is in your schema
// if you're using any of the accounts packages
services: {
@ -103,7 +91,26 @@ const schemaUser = new SimpleSchema({
slug: {
type: String,
optional: true
}
},
profile: {
type: schemaUserProfile,
optional: true,
blackbox: true
},
// https://guide.meteor.com/accounts.html#custom-user-data
/* Our users has a name of type Object while Google Service, for instance, not */
/* name: { type: String, optional: true }, */
/* name: Object,
'name.first': String,
'name.last': String, */
lang: { type: String, optional: true },
telegramChatId: { type: Number, optional: true },
telegramUsername: { type: String, optional: true },
telegramFirstName: { type: String, optional: true },
telegramLanguageCode: { type: String, optional: true },
createdAt: defaultCreatedAt,
updatedAt: defaultUpdateAt
});
Meteor.users.attachSchema(schemaUser);

View file

@ -4,3 +4,4 @@ import './api';
import './fixtures';
import './email';
import './IPGeocoder';
import './migrations';

View file

@ -0,0 +1,31 @@
/* global Migrations */
/* eslint-disable import/no-absolute-path */
import { Meteor } from 'meteor/meteor';
Meteor.startup(() => {
// https://github.com/percolatestudio/meteor-migrations
Migrations.config({
// Log job run details to console
log: true
});
Migrations.add({
version: 1,
up: function migrateIds() {
// https://docs.mongodb.com/manual/reference/operator/query/type/
Meteor.users.find({ _id: { $type: 7 } }).forEach((user) => {
const migratedUser = user;
const id = user._id.valueOf();
console.log(`Migrating id of user: ${JSON.stringify(user)}`);
Meteor.users.remove({ _id: user._id });
migratedUser._id = id;
Meteor.users.insert(migratedUser);
});
}
});
Migrations.migrateTo('latest');
// Migrations.migrateTo('1,rerun');
});

View file

@ -16,7 +16,7 @@ class Login extends React.Component {
super(props);
this.t = props.t;
this.handleSubmit = this.handleSubmit.bind(this);
console.log(this.props.location.state);
// console.log(this.props.location.state);
this.state = props.location.state;
}

View file

@ -8,7 +8,7 @@ import { Link } from 'react-router-dom';
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { Bert } from 'meteor/themeteorchef:bert';
import randomHex from 'random-hexadecimal';
import randomHex from 'crypto-random-hex';
import Icon from '../../components/Icon/Icon';
import OAuthLoginButtons from '../../components/OAuthLoginButtons/OAuthLoginButtons';
import InputHint from '../../components/InputHint/InputHint';
@ -86,7 +86,6 @@ class Signup extends React.Component {
Meteor.call('users.sendVerificationEmail');
Bert.alert(t('Bienvenid@!'), 'success');
history.push('/subscriptions');
}
});
}
@ -102,7 +101,7 @@ class Signup extends React.Component {
<button
className="btn btn-block btn-raised btn-primary OAuthLoginButtonDis OAuthLoginButton-telegram"
type="button"
onClick={() => { const hex = randomHex({ max: 20 }); window.open(`https://t.me/TodosContraElFuego_bot?start=${hex}`); }}
onClick={() => { const hex = randomHex(20); console.log(hex); window.open(`https://t.me/TodosContraElFuego_bot?start=${hex}`); }}
>
<span><Icon icon="telegram" /> {t('Iniciar sesión con Telegram')}</span>
</button>