-
Notifications
You must be signed in to change notification settings - Fork 0
/
codywebstoredproc.sql
72 lines (54 loc) · 5.92 KB
/
codywebstoredproc.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
DELIMITER //
DROP PROCEDURE IF EXISTS createWebsite
//
CREATE PROCEDURE createWebsite(IN siteName VARCHAR(255), IN pass VARCHAR(255), IN email VARCHAR(255))
BEGIN
SET @sql = CONCAT('CREATE DATABASE ', siteName, ';');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('CREATE TABLE %newdb%.%tablename% LIKE %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'atoms'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('INSERT INTO %newdb%.%tablename% SELECT * FROM %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'atoms'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('CREATE TABLE %newdb%.%tablename% LIKE %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'content'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('INSERT INTO %newdb%.%tablename% SELECT * FROM %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'content'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('CREATE TABLE %newdb%.%tablename% LIKE %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'domains'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('INSERT INTO %newdb%.%tablename% SELECT * FROM %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'domains'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('CREATE TABLE %newdb%.%tablename% LIKE %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'items'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('INSERT INTO %newdb%.%tablename% SELECT * FROM %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'items'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('CREATE TABLE %newdb%.%tablename% LIKE %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'languages'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('INSERT INTO %newdb%.%tablename% SELECT * FROM %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'languages'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('CREATE TABLE %newdb%.%tablename% LIKE %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'levels'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('INSERT INTO %newdb%.%tablename% SELECT * FROM %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'levels'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('CREATE TABLE %newdb%.%tablename% LIKE %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'pages'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('INSERT INTO %newdb%.%tablename% SELECT * FROM %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'pages'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('CREATE TABLE %newdb%.%tablename% LIKE %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'templates'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('INSERT INTO %newdb%.%tablename% SELECT * FROM %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'templates'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('CREATE TABLE %newdb%.%tablename% LIKE %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'users'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('INSERT INTO %newdb%.%tablename% SELECT * FROM %template%.%tablename%;', '%newdb%', siteName), '%tablename%', 'users'), '%template%', 'empty');
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE('DELETE FROM %newdb%.users', '%newdb%', siteName);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('INSERT INTO %newdb%.users (username, name, password, domain, level, active, email) VALUES(\'admin\', \'admin\', \'%pass%\', \'users\', \'99\', \'Y\', \'%email%\')', '%pass%', pass), '%newdb%', siteName), '%email%', email);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('GRANT ALL ON %newdb%.* TO \'%sitename%\'@\'%\' IDENTIFIED BY \'%pass%\'', '%newdb%', siteName), '%pass%', pass), '%sitename%', siteName);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = REPLACE(REPLACE(REPLACE('GRANT ALL ON %newdb%.* TO \'%sitename%\'@\'localhost\' IDENTIFIED BY \'%pass%\'', '%newdb%', siteName), '%pass%', pass), '%sitename%', siteName);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
SET @sql = 'FLUSH PRIVILEGES;';
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
END//