Primary init

In most applications, after installation, you must make an primary database initialization. It is necessary to add an administrator and other params. Start initialization by a separate script.


(async ()=> {
  const SystemHelper = require('areto/helper/SystemHelper');
  const Migrator = require('areto/db/Migrator');
  const Application = require('../Application');
  const application = new Application;
  try {
    const data = SystemHelper.parseArguments(process.argv);
    await application.init();
    const migrator = new Migrator({module: application});
    await migrator.migrate(data.action, data.file);
  } catch (err) {
    application.logError('Migration error', err);

Create the migrations directory and add the Init class to it. Class will create the Administrator user with the admin role. In the future, administrator can sign in to the application control module and create other users by web interface.


const Base = require('areto/db/Migration');
module.exports = class Init extends Base {
  async apply () {
    await this.getDb().createIndex('user', [{email: 1}, {unique: true}]);
    const user = this.spawn(User);
      name: 'Administrator',
      email: 'a@a.a',
      role: 'admin',
      password: '123456'

You can run a script either from command line, go to the blog directory:

node console/init.js apply migrations/Init

Either using Visual Studio Code:

Name: Init Areto Blog
Working directory: areto-blog
Javascript file: console/init.js
Application parameters: apply migrations/Init