Created
August 26, 2018 20:31
-
-
Save bingomanatee/c6fd01c4d5a95b88d912baae8ef7658f to your computer and use it in GitHub Desktop.
Article Migration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = { | |
async up(queryInterface, Sequelize) { | |
const { sequelize } = queryInterface; | |
await sequelize.query('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";'); | |
return sequelize.transaction(async (transaction) => { | |
await queryInterface.createTable('articles', { | |
id: { | |
type: Sequelize.UUID, | |
primaryKey: true, | |
allowNull: false, | |
defaultValue: Sequelize.UUIDV4, | |
}, | |
title: { | |
allowNull: false, | |
type: Sequelize.CHAR(80) | |
}, | |
version: { | |
allowNull: false, | |
type: Sequelize.INTEGER, | |
}, | |
directory: { | |
allowNull: false, | |
type: Sequelize.CHAR(80), | |
}, | |
path: { | |
allowNull: false, | |
type: Sequelize.CHAR(160), | |
}, | |
sha: { | |
allowNull: false, | |
type: Sequelize.CHAR(160), | |
}, | |
meta: { | |
allowNull: false, | |
type: Sequelize.JSON | |
}, | |
description: { | |
allowNull: false, | |
type: Sequelize.TEXT, | |
}, | |
content: { | |
allowNull: false, | |
type: Sequelize.TEXT, | |
}, | |
published: { | |
allowNull: false, | |
type: Sequelize.BOOLEAN, | |
defaultValue: false | |
}, | |
on_homepage: { | |
allowNull: false, | |
type: Sequelize.BOOLEAN, | |
defaultValue: false | |
}, | |
file_created: { | |
allowNull: false, | |
type: Sequelize.DATE, | |
defaultValue: Sequelize.fn('NOW'), | |
}, | |
file_revised: { | |
allowNull: false, | |
type: Sequelize.DATE, | |
defaultValue: Sequelize.fn('NOW'), | |
}, | |
createdAt: { | |
allowNull: false, | |
type: Sequelize.DATE, | |
}, | |
updatedAt: { | |
allowNull: false, | |
type: Sequelize.DATE, | |
}, | |
deletedAt: { | |
type: Sequelize.DATE, | |
allowNull: true, | |
defaultValue: null, | |
}, | |
}, { transaction }); | |
}); | |
}, | |
async down(queryInterface) { | |
const { sequelize } = queryInterface; | |
return sequelize.transaction(async (transaction) => { | |
await queryInterface.dropTable('articles', { transaction }); | |
}); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Produces -- Table: public.articles
-- DROP TABLE public.articles;
CREATE TABLE public.articles
(
id uuid NOT NULL,
title character(80) COLLATE pg_catalog."default" NOT NULL,
version integer NOT NULL,
directory character(80) COLLATE pg_catalog."default" NOT NULL,
path character(160) COLLATE pg_catalog."default" NOT NULL,
sha character(160) COLLATE pg_catalog."default" NOT NULL,
meta json NOT NULL,
description text COLLATE pg_catalog."default" NOT NULL,
content text COLLATE pg_catalog."default" NOT NULL,
published boolean NOT NULL DEFAULT false,
on_homepage boolean NOT NULL DEFAULT false,
file_created timestamp with time zone NOT NULL DEFAULT now(),
file_revised timestamp with time zone NOT NULL DEFAULT now(),
"createdAt" timestamp with time zone NOT NULL,
"updatedAt" timestamp with time zone NOT NULL,
"deletedAt" timestamp with time zone,
CONSTRAINT articles_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public.articles
OWNER to root;