You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cvm/migrations/20160906073423_initial.js

92 lines
4.1 KiB
JavaScript

'use strict';
exports.up = function(knex, Promise) {
return knex.schema
.createTable("users", (table) => {
table.bigIncrements("id").primary();
table.text("username").notNullable();
table.text("hash").notNullable();
table.text("email_address").notNullable();
table.boolean("is_active").notNullable();
table.timestamp("created_at").notNullable().defaultTo(knex.fn.now());
})
.createTable("storage_pools", (table) => {
table.bigIncrements("id").primary();
table.text("type").notNullable(); // lvm, folder
table.text("name"); // for lvm VG name
table.text("path"); // for folder base path
table.boolean("is_local").notNullable(); // to prevent trying to attach a storage volume that lives on the wrong host
table.timestamp("created_at").notNullable().defaultTo(knex.fn.now());
})
.createTable("instance_types", (table) => {
table.bigIncrements("id").primary();
table.text("name").notNullable();
table.text("internal_comment");
table.integer("default_memory").notNullable(); // in MB
table.integer("default_disk_space").notNullable(); // in MB
table.integer("default_traffic"); // in MB
table.timestamp("created_at").notNullable().defaultTo(knex.fn.now());
})
.createTable("allowed_storage_pools", (table) => {
table.bigInteger("instance_type_id").notNullable().references("instance_types.id");
table.bigInteger("storage_pool_id").notNullable().references("storage_pools.id");
table.unique([ "instance_type_id", "storage_pool_id" ]);
})
.createTable("images", (table) => {
table.bigIncrements("id").primary();
table.bigInteger("user_id").notNullable().references("users.id"); // user that added it
// table.uuid("file_id").notNullable();
table.text("name");
table.text("description");
table.text("source_type").notNullable(); // local, http, upload
table.text("source"); // URL, path, etc.
table.boolean("is_public").notNullable(); // whether the image should be visible to everybody, or just its owner
table.boolean("is_install_medium").notNullable(); // whether the image is just for installation (if not, it will be directly clonable)
table.timestamp("created_at").notNullable().defaultTo(knex.fn.now());
})
.createTable("instances", (table) => {
table.bigIncrements("id").primary();
table.bigInteger("user_id").notNullable().references("users.id");
table.bigInteger("mounted_image_id").references("images.id");
table.bigInteger("last_installation_media_id").references("images.id");
table.jsonb("boot_order").notNullable(); // array that includes references to storage volumes!
// table.uuid("instance_uuid").notNullable();
table.text("name");
table.text("comment");
table.integer("memory").notNullable(); // in MB
table.integer("disk_space").notNullable(); // in MB
table.integer("traffic"); // in MB
table.boolean("is_suspended").notNullable();
table.text("suspension_reason");
table.boolean("is_terminated").notNullable();
table.text("termination_reason");
table.boolean("is_running");
table.timestamp("created_at").notNullable().defaultTo(knex.fn.now());
})
.createTable("storage_volumes", (table) => {
table.bigIncrements("id").primary();
table.bigInteger("user_id").references("users.id");
table.bigInteger("storage_pool_id").references("storage_pools.id");
// table.uuid("volume_uuid").notNullable();
table.text("format").notNullable(); // qcow2
table.timestamp("created_at").notNullable().defaultTo(knex.fn.now());
})
.createTable("storage_attachments", (table) => {
table.bigInteger("storage_volume_id").notNullable().references("storage_volumes.id").unique();
table.bigInteger("instance_id").notNullable().references("storage_volumes.id");
table.boolean("is_locked").notNullable(); // whether the user should be prevented from detaching this storage volume
});
};
exports.down = function(knex, Promise) {
return knex.schema
.dropTable("storage_attachments")
.dropTable("storage_volumes")
.dropTable("instances")
.dropTable("images")
.dropTable("allowed_storage_pools")
.dropTable("instance_types")
.dropTable("storage_pools")
.dropTable("users");
};