· 7 years ago · Oct 01, 2018, 10:18 PM
1import os
2import re
3import time
4import logging
5
6tenant_name = 'tenant_name' #args.tenant_name
7
8def do_schemaImport(directory):
9for filename in os.listdir(directory):
10 directory = dir
11 schema = os.path.basename(filename, ".sql")
12 new_schema = schema + '_' + tenant_name
13
14f1 = open(filename, 'r')
15f2 = open(dir + "/" + new_schema + ".sql", 'w')
16
17for line in f1:
18 if re.match(r"DROP DATABASE{1}|^USE{1}|CREATE DATABASE{1}", f1) in line:
19 line.replace(schema, new_schema)
20 logging.info(line)
21
22 if re.match(r"ENGINE=INNODB", f1) in line and re.match(r";","ROW_FORMAT=COMPRESSED;", f1):
23 line = line.replace("ROW_FORMAT=COMPRESSED;")
24 f2.write(line)
25
26f1.close()
27f2.close()
28
29CREATE DATABASE /*!32312 IF NOT EXISTS*/ `configurationservice` /*!40100
30DEFAULT CHARACTER SET utf8 */;
31
32USE `configurationservice`;
33
34--
35-- Table structure for table `class`
36--
37
38 DROP TABLE IF EXISTS `class`;
39 /*!40101 SET @saved_cs_client = @@character_set_client */;
40 /*!40101 SET character_set_client = utf8 */;
41 CREATE TABLE `class` (
42`class_id` bigint(20) NOT NULL AUTO_INCREMENT,
43 `value` varchar(255) NOT NULL,
44 PRIMARY KEY (`class_id`),
45 UNIQUE KEY `XIE1EVENTDATACLASSVALUE` (`value`)
46 ) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8
47ROW_FORMAT=COMPRESSED;
48 /*!40101 SET character_set_client = @saved_cs_client */;