• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1def migrate_up(manager):
2    """migrate up the database schema.
3
4    @param manager: Instance of MigrationManager.
5    """
6    manager.execute_script(INIT_DB_SQL)
7    manager.execute_script(INIT_VERSION_SQL)
8
9
10def migrate_down(manager):
11    """migrate down the database schema.
12
13    @param manager: Instance of MigrationManager.
14    """
15    manager.execute_script(DROP_DB_SQL)
16
17
18INIT_VERSION_SQL = """\
19INSERT INTO migrate_info VALUES (0)
20"""
21
22INIT_DB_SQL = """\
23-- MySQL dump 10.13  Distrib 5.5.40, for debian-linux-gnu (x86_64)
24--
25-- Host: localhost    Database: chromeos_lab_servers
26-- ------------------------------------------------------
27-- Server version       5.5.40-0ubuntu0.14.04.1
28
29/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
30/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
31/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
32/*!40101 SET NAMES utf8 */;
33/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
34/*!40103 SET TIME_ZONE='+00:00' */;
35/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
36/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
37/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
38/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
39
40--
41-- Table structure for table `migrate_info`
42--
43
44DROP TABLE IF EXISTS `migrate_info`;
45/*!40101 SET @saved_cs_client     = @@character_set_client */;
46/*!40101 SET character_set_client = utf8 */;
47CREATE TABLE `migrate_info` (
48  `version` int(11) DEFAULT NULL
49) ENGINE=InnoDB DEFAULT CHARSET=latin1;
50/*!40101 SET character_set_client = @saved_cs_client */;
51
52--
53-- Table structure for table `server_roles`
54--
55
56DROP TABLE IF EXISTS `server_roles`;
57/*!40101 SET @saved_cs_client     = @@character_set_client */;
58/*!40101 SET character_set_client = utf8 */;
59CREATE TABLE `server_roles` (
60  `id` int(11) NOT NULL auto_increment,
61  `server_id` int(11) DEFAULT NULL,
62  `role` varchar(128) DEFAULT NULL,
63  PRIMARY KEY (`id`),
64  KEY `fk_server_roles_server_idx` (`server_id`),
65  CONSTRAINT `fk_server_roles_server` FOREIGN KEY (`server_id`) REFERENCES `servers` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
66) ENGINE=InnoDB DEFAULT CHARSET=latin1;
67/*!40101 SET character_set_client = @saved_cs_client */;
68
69--
70-- Table structure for table `servers`
71--
72
73DROP TABLE IF EXISTS `servers`;
74/*!40101 SET @saved_cs_client     = @@character_set_client */;
75/*!40101 SET character_set_client = utf8 */;
76CREATE TABLE `servers` (
77  `id` int(11) NOT NULL auto_increment,
78  `hostname` varchar(128) NOT NULL,
79  `cname` varchar(128) DEFAULT NULL,
80  `status` varchar(128) DEFAULT NULL,
81  `date_created` datetime DEFAULT NULL,
82  `date_modified` datetime DEFAULT NULL,
83  `note` text,
84  PRIMARY KEY (`id`),
85  UNIQUE KEY `hostname_UNIQUE` (`hostname`),
86  UNIQUE KEY `cname_UNIQUE` (`cname`)
87) ENGINE=InnoDB DEFAULT CHARSET=latin1;
88/*!40101 SET character_set_client = @saved_cs_client */;
89/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
90
91/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
92/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
93/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
94/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
95/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
96/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
97/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
98
99-- Dump completed on 2014-10-28 12:08:40
100"""
101
102DROP_DB_SQL = """\
103DROP TABLE IF EXISTS `server_roles`;
104DROP TABLE IF EXISTS `servers`;
105"""
106