Skip to content
This repository has been archived by the owner on Apr 4, 2020. It is now read-only.

MongoDB migrations command-line interface

License

Notifications You must be signed in to change notification settings

Minespree/UpdateMongoClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Migrations

Discord License Documentation

This is the code that powered the MongoDB migrations command-line interface of the former Minespree Network. It includes multiple scripts we had to migrate user/application data to a new schema.

Besides the removal of some branding and configuration data, it is more or less unmodified. It is probably not directly useful to third parties in its current state, but it may be help in understanding how the Minespree network operated.

We are quite open to the idea of evolving this into something more generally useful. If you would like to contribute to this effort, talk to us in Discord.

Please note that this project might have legacy code that was planned to be refactored and as so, we kindly ask you not to judge the programming skills of the author(s) based on this single codebase.

Requirements

To build Migrations, the following will need to be installed and available from your shell:

  • JDK 8 version 131 or later (older versions might work)
  • Git
  • Maven

You can find detailed installation instructions for these tools on the Getting started docs page.

Getting started

You can build this project using Maven:

mvn package

Next, start up the CLI by running on a terminal:

java -jar migration-manager-1.0.0.jar

The app will now ask you for database details (IP, port, username, password and database name) and what migrations you want to run.

In order to add more migrations, create a class inside of the impls package that extends the Migration class and add it to the MIGRATIONS array on the MigrationManager class. Here's an example migration that removes the "trash" field from each player's document:

public class CleanupMigration extends Migration {
    public CleanupMigration(MigrationManager manager) {
        super("Cleanup", manager);
    }

    @Override
    public boolean init() {
        MongoCollection<Document> collection = manager.getCollection("players");

        long total = collection.count();
        migrationCount(total);

        FindIterable<Document> all = collection.find();
        List<UpdateOneModel<Document>> updates = new ArrayList<>();

        Document unsetDoc = new Document();
        unsetDoc.put("trash", "");

        for (Document document : all) {
            updates.add(new UpdateOneModel<>(
                    Filters.eq("_id", document.get("_id")),
                    new Document("$unset", unsetDoc),
                    OPTIONS
            ));
        }

        BulkWriteResult result = collection.bulkWrite(updates);

        return result.wasAcknowledged();
    }
}

Architecture

This repo contains the following components:

  • Base classes and CLI to run migrations
  • Various migrations we had to run whenever our other projects required database schema changes (check each migration's javadocs for details)

Authors

This project was maintained by the Minespree Network team. If you have any questions or problems, feel free to reach out to the specific writers and maintainers of this project:


Hugmanrique

exception

Coding Conventions

  • We generally follow the Sun/Oracle coding standards.
  • No tabs; use 4 spaces instead
  • No trailing whitespaces
  • No CRLF line endings, LF only, put your git's core.autocrlf on true.
  • No 80 column limit or 'weird' midstatement newlines.

License

Migrations is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

A copy of the GNU Affero General Public License is included in the file LICENSE, and can also be found at https://www.gnu.org/licenses/agpl-3.0.en.html

The AGPL license is quite restrictive, please make sure you understand it. If you run a modified version of this software as a network service, anyone who can use that service must also have access to the modified source code.

About

MongoDB migrations command-line interface

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages