Giter Club home page Giter Club logo

marvin-bot's Introduction

Marvin - a depressed bot

Database migrations

This project uses Flyway for migrations. The decision has been made to keep the PostgreSQL sequence generation instead of the global one sequence to rule them all of Hibernate.

The ability for Hibernate to automagically update the database for you has been disabled. Any changes to the database schema has to be done manually, and a migration made.

To make a new migration create a new entity. The convention for tables and columns matches those of Ruby on Rails, not the default Hibernate/JPA of just naming it exactly after the class.

An example entity with a custom set table name and a PostgreSQL table sequence.

@Entity
@Table(name = "commands")
public class Command {

    @Id
    // This line creates a sequence `commands_id_seq` that is for the field `id` in the table `commands`.
    @SequenceGenerator(name = "pk_sequence", sequenceName = "commands_id_seq")
    // Wire the sequence up to the id.
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "pk_sequence")
    private long id;
    @Column(unique = true)
    private String name;
    private String endpoint;

    private RequestMethod method;
}

In development mode any new entity will automatically generate a new table with the correct fields on it. You can then copy the table definition to a new migration.

Note: Tests are run in their own profile and they rely on all database changes to happen through a migration.

The migration file for the above entity is named V1__Add_commands_table.sql and contained at the time of writing:

CREATE TABLE commands
(
    id BIGSERIAL,  -- This is PostgreSQL syntax for a bigint primary key with its own serial sequence.
    endpoint VARCHAR(255),
    method INTEGER,
    name VARCHAR(255)
);
CREATE UNIQUE INDEX uk_py1b1n9yenhsrtlh4gj3p7b4g ON commands (name);

Running migrations

Flyway will automatically migrate the database to the latest version on boot.

Build failing from mossing accessors?

It's probably because IntelliJ hasn't been configured to support annotation processors.

Do so by:

  1. Opening the settings window for "Annotation processors"
  2. Click "Enable annotation processors"
  3. Recompile the entire project

marvin-bot's People

Contributors

gaqzi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.