diff --git a/pom.xml b/pom.xml
index 3be1e6dacace2533ab5cf717a3570e9b93a9a43b..c6188a257460c5a0aec4895581dea96db9786376 100755
--- a/pom.xml
+++ b/pom.xml
@@ -52,6 +52,11 @@
       <version>3.0.9.Final</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+        <groupId>org.flywaydb</groupId>
+        <artifactId>flyway-core</artifactId>
+        <version>4.2.0</version>
+    </dependency>
   </dependencies>
 
   <build>
diff --git a/src/main/java/no/nibio/vips/coremanager/startup/StartupListener.java b/src/main/java/no/nibio/vips/coremanager/startup/StartupListener.java
new file mode 100644
index 0000000000000000000000000000000000000000..b9095df3857ddc5da710c86357d3ace57da1b082
--- /dev/null
+++ b/src/main/java/no/nibio/vips/coremanager/startup/StartupListener.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2017 NIBIO <http://www.nibio.no/>. 
+ * 
+ * This file is part of VIPSCoreManager.
+ * VIPSCoreManager is free software: you can redistribute it and/or modify
+ * it under the terms of the NIBIO Open Source License as published by 
+ * NIBIO, either version 1 of the License, or (at your option) any
+ * later version.
+ * 
+ * VIPSCoreManager 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
+ * NIBIO Open Source License for more details.
+ * 
+ * You should have received a copy of the NIBIO Open Source License
+ * along with VIPSCoreManager.  If not, see <http://www.nibio.no/licenses/>.
+ * 
+ */
+
+package no.nibio.vips.coremanager.startup;
+
+import javax.annotation.Resource;
+import javax.servlet.ServletContextEvent;
+import javax.sql.DataSource;
+import org.flywaydb.core.Flyway;
+
+/**
+ * This class is created and method contextInitialized called when the application
+ * is deployed (either at startup of application container or when redeploying the app)
+ * 
+ * @copyright 2017 <a href="http://www.nibio.no/">NIBIO</a>
+ * @author Tor-Einar Skog <tor-einar.skog@nibio.no>
+ */
+public class StartupListener implements javax.servlet.ServletContextListener {
+    @Resource(lookup="java:/jboss/datasources/vipscoremanager")
+    DataSource vipscoremanagerDS;
+
+    @Override
+    public void contextInitialized(ServletContextEvent sce) {
+        System.out.println("VIPSCoreManager system initializing");
+        System.out.println("VIPSCoreManager checking for database migrations");
+        // Migrate DB on startup using flywaydb.org
+        Flyway flyway = new Flyway();
+        flyway.setDataSource(vipscoremanagerDS);
+        flyway.migrate();
+    }
+
+    @Override
+    public void contextDestroyed(ServletContextEvent sce) {
+        System.out.println("VIPSCoreManager system shutting down");
+    }
+}
diff --git a/src/main/resources/db/migration/V1__Base_version.sql b/src/main/resources/db/migration/V1__Base_version.sql
new file mode 100644
index 0000000000000000000000000000000000000000..bca5846dc046198f78bb6396543671e0c63d19d7
--- /dev/null
+++ b/src/main/resources/db/migration/V1__Base_version.sql
@@ -0,0 +1,305 @@
+/* 
+ * Copyright (c) 2017 NIBIO <http://www.nibio.no/>. 
+ * 
+ * This file is part of VIPSCoreManager.
+ * VIPSCoreManager is free software: you can redistribute it and/or modify
+ * it under the terms of the NIBIO Open Source License as published by 
+ * NIBIO, either version 1 of the License, or (at your option) any
+ * later version.
+ * 
+ * VIPSCoreManager 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
+ * NIBIO Open Source License for more details.
+ * 
+ * You should have received a copy of the NIBIO Open Source License
+ * along with VIPSCoreManager.  If not, see <http://www.nibio.no/licenses/>.
+ * 
+ */
+/**
+ * Author:  treinar
+ * Created: Oct 11, 2017
+ */
+
+--
+-- PostgreSQL database dump
+--
+
+-- Dumped from database version 9.5.9
+-- Dumped by pg_dump version 9.5.8
+
+-- Started on 2017-10-10 15:02:31 CEST
+
+SET statement_timeout = 0;
+SET lock_timeout = 0;
+SET client_encoding = 'UTF8';
+SET standard_conforming_strings = on;
+SET check_function_bodies = false;
+SET client_min_messages = warning;
+SET row_security = off;
+
+SET search_path = public, pg_catalog;
+
+SET default_tablespace = '';
+
+SET default_with_oids = false;
+
+--
+-- TOC entry 182 (class 1259 OID 16389)
+-- Name: model_usage_log; Type: TABLE; Schema: public; Owner: vipscoremanager
+--
+
+CREATE TABLE model_usage_log (
+    model_usage_id integer NOT NULL,
+    model_id character(10),
+    time_started timestamp with time zone,
+    status_code integer,
+    message character varying(2047),
+    vips_core_user_id integer,
+    time_finished timestamp with time zone
+);
+
+
+ALTER TABLE model_usage_log OWNER TO vipscoremanager;
+
+--
+-- TOC entry 183 (class 1259 OID 16395)
+-- Name: model_usage_log_model_usage_id_seq; Type: SEQUENCE; Schema: public; Owner: vipscoremanager
+--
+
+CREATE SEQUENCE model_usage_log_model_usage_id_seq
+    START WITH 1
+    INCREMENT BY 1
+    NO MINVALUE
+    NO MAXVALUE
+    CACHE 1;
+
+
+ALTER TABLE model_usage_log_model_usage_id_seq OWNER TO vipscoremanager;
+
+--
+-- TOC entry 2156 (class 0 OID 0)
+-- Dependencies: 183
+-- Name: model_usage_log_model_usage_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: vipscoremanager
+--
+
+ALTER SEQUENCE model_usage_log_model_usage_id_seq OWNED BY model_usage_log.model_usage_id;
+
+
+--
+-- TOC entry 184 (class 1259 OID 16397)
+-- Name: organization; Type: TABLE; Schema: public; Owner: vipscoremanager
+--
+
+CREATE TABLE organization (
+    organization_id integer NOT NULL,
+    organization_name character varying(255),
+    parent_organization_id integer
+);
+
+
+ALTER TABLE organization OWNER TO vipscoremanager;
+
+--
+-- TOC entry 185 (class 1259 OID 16400)
+-- Name: organization_organization_id_seq; Type: SEQUENCE; Schema: public; Owner: vipscoremanager
+--
+
+CREATE SEQUENCE organization_organization_id_seq
+    START WITH 1
+    INCREMENT BY 1
+    NO MINVALUE
+    NO MAXVALUE
+    CACHE 1;
+
+
+ALTER TABLE organization_organization_id_seq OWNER TO vipscoremanager;
+
+--
+-- TOC entry 2157 (class 0 OID 0)
+-- Dependencies: 185
+-- Name: organization_organization_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: vipscoremanager
+--
+
+ALTER SEQUENCE organization_organization_id_seq OWNED BY organization.organization_id;
+
+
+--
+-- TOC entry 186 (class 1259 OID 16402)
+-- Name: vips_core_credentials; Type: TABLE; Schema: public; Owner: vipscoremanager
+--
+
+CREATE TABLE vips_core_credentials (
+    id integer NOT NULL,
+    username character varying(255),
+    password character varying(255),
+    vips_core_user_id integer
+);
+
+
+ALTER TABLE vips_core_credentials OWNER TO vipscoremanager;
+
+--
+-- TOC entry 187 (class 1259 OID 16408)
+-- Name: vips_core_credentials_id_seq; Type: SEQUENCE; Schema: public; Owner: vipscoremanager
+--
+
+CREATE SEQUENCE vips_core_credentials_id_seq
+    START WITH 1
+    INCREMENT BY 1
+    NO MINVALUE
+    NO MAXVALUE
+    CACHE 1;
+
+
+ALTER TABLE vips_core_credentials_id_seq OWNER TO vipscoremanager;
+
+--
+-- TOC entry 2158 (class 0 OID 0)
+-- Dependencies: 187
+-- Name: vips_core_credentials_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: vipscoremanager
+--
+
+ALTER SEQUENCE vips_core_credentials_id_seq OWNED BY vips_core_credentials.id;
+
+
+--
+-- TOC entry 188 (class 1259 OID 16410)
+-- Name: vips_core_user; Type: TABLE; Schema: public; Owner: vipscoremanager
+--
+
+CREATE TABLE vips_core_user (
+    vips_core_user_id integer NOT NULL,
+    first_name character varying(255),
+    last_name character varying(255),
+    organization_id integer
+);
+
+
+ALTER TABLE vips_core_user OWNER TO vipscoremanager;
+
+--
+-- TOC entry 189 (class 1259 OID 16416)
+-- Name: vips_core_user_vips_core_user_id_seq; Type: SEQUENCE; Schema: public; Owner: vipscoremanager
+--
+
+CREATE SEQUENCE vips_core_user_vips_core_user_id_seq
+    START WITH 1
+    INCREMENT BY 1
+    NO MINVALUE
+    NO MAXVALUE
+    CACHE 1;
+
+
+ALTER TABLE vips_core_user_vips_core_user_id_seq OWNER TO vipscoremanager;
+
+--
+-- TOC entry 2159 (class 0 OID 0)
+-- Dependencies: 189
+-- Name: vips_core_user_vips_core_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: vipscoremanager
+--
+
+ALTER SEQUENCE vips_core_user_vips_core_user_id_seq OWNED BY vips_core_user.vips_core_user_id;
+
+
+--
+-- TOC entry 2010 (class 2604 OID 16418)
+-- Name: model_usage_id; Type: DEFAULT; Schema: public; Owner: vipscoremanager
+--
+
+ALTER TABLE ONLY model_usage_log ALTER COLUMN model_usage_id SET DEFAULT nextval('model_usage_log_model_usage_id_seq'::regclass);
+
+
+--
+-- TOC entry 2011 (class 2604 OID 16419)
+-- Name: organization_id; Type: DEFAULT; Schema: public; Owner: vipscoremanager
+--
+
+ALTER TABLE ONLY organization ALTER COLUMN organization_id SET DEFAULT nextval('organization_organization_id_seq'::regclass);
+
+
+--
+-- TOC entry 2012 (class 2604 OID 16420)
+-- Name: id; Type: DEFAULT; Schema: public; Owner: vipscoremanager
+--
+
+ALTER TABLE ONLY vips_core_credentials ALTER COLUMN id SET DEFAULT nextval('vips_core_credentials_id_seq'::regclass);
+
+
+--
+-- TOC entry 2013 (class 2604 OID 16421)
+-- Name: vips_core_user_id; Type: DEFAULT; Schema: public; Owner: vipscoremanager
+--
+
+ALTER TABLE ONLY vips_core_user ALTER COLUMN vips_core_user_id SET DEFAULT nextval('vips_core_user_vips_core_user_id_seq'::regclass);
+
+
+--
+-- TOC entry 2015 (class 2606 OID 16423)
+-- Name: model_usage_log_pkey; Type: CONSTRAINT; Schema: public; Owner: vipscoremanager
+--
+
+ALTER TABLE ONLY model_usage_log
+    ADD CONSTRAINT model_usage_log_pkey PRIMARY KEY (model_usage_id);
+
+
+--
+-- TOC entry 2017 (class 2606 OID 16425)
+-- Name: organization_pkey; Type: CONSTRAINT; Schema: public; Owner: vipscoremanager
+--
+
+ALTER TABLE ONLY organization
+    ADD CONSTRAINT organization_pkey PRIMARY KEY (organization_id);
+
+
+--
+-- TOC entry 2019 (class 2606 OID 16427)
+-- Name: vips_core_credentials_pkey; Type: CONSTRAINT; Schema: public; Owner: vipscoremanager
+--
+
+ALTER TABLE ONLY vips_core_credentials
+    ADD CONSTRAINT vips_core_credentials_pkey PRIMARY KEY (id);
+
+
+--
+-- TOC entry 2021 (class 2606 OID 16429)
+-- Name: vips_core_user_pkey; Type: CONSTRAINT; Schema: public; Owner: vipscoremanager
+--
+
+ALTER TABLE ONLY vips_core_user
+    ADD CONSTRAINT vips_core_user_pkey PRIMARY KEY (vips_core_user_id);
+
+
+--
+-- TOC entry 2022 (class 2606 OID 16430)
+-- Name: model_usage_log_vips_core_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: vipscoremanager
+--
+
+ALTER TABLE ONLY model_usage_log
+    ADD CONSTRAINT model_usage_log_vips_core_user_id_fkey FOREIGN KEY (vips_core_user_id) REFERENCES vips_core_user(vips_core_user_id);
+
+
+--
+-- TOC entry 2023 (class 2606 OID 16435)
+-- Name: vips_core_credentials_vips_core_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: vipscoremanager
+--
+
+ALTER TABLE ONLY vips_core_credentials
+    ADD CONSTRAINT vips_core_credentials_vips_core_user_id_fkey FOREIGN KEY (vips_core_user_id) REFERENCES vips_core_user(vips_core_user_id);
+
+
+--
+-- TOC entry 2024 (class 2606 OID 16440)
+-- Name: vips_core_user_organization_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: vipscoremanager
+--
+
+ALTER TABLE ONLY vips_core_user
+    ADD CONSTRAINT vips_core_user_organization_id_fkey FOREIGN KEY (organization_id) REFERENCES organization(organization_id);
+
+-- Completed on 2017-10-10 15:02:40 CEST
+
+--
+-- PostgreSQL database dump complete
+--
+
+
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index 12e93c5e4e646e91faa437b86f5898496c38a7c5..e29d5a42867f92e39b8da969c363590cf2b08170 100755
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -51,4 +51,7 @@
             </transport-guarantee>
         </user-data-constraint>
     </security-constraint-->
+    <listener>
+        <listener-class>no.nibio.vips.coremanager.startup.StartupListener</listener-class>
+    </listener>
 </web-app>