-
Notifications
You must be signed in to change notification settings - Fork 0
denormalized query tables #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| tutorial-env | ||
| __pycache__ | ||
| test.sublime-workspace | ||
| clearDatabase.py | ||
| testFaker.py | ||
| clearDatabase.py |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,14 +9,14 @@ def createTables(): | |
| " `site` varchar(20) NOT NULL," | ||
| " `text` longtext NOT NULL," | ||
| " `published` timestamp NOT NULL," | ||
| # " `published` int(11) NOT NULL," | ||
| " `ES` tinyint(1) NOT NULL," | ||
| " `US` tinyint(1) NOT NULL," | ||
| " `MX` tinyint(1) NOT NULL," | ||
| " `CO` tinyint(1) NOT NULL," | ||
| " `type` varchar(100) NOT NULL," | ||
| " `type` enum('normal', 'ecommerce', 'slideshow', 'video', 'duplicate', 'branded_club', 'brand_article', 'brand_article_video', 'longform', 'reposted_slideshow') NOT NULL DEFAULT 'normal'," | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i suggest to take it string instead of enum. |
||
| " `url` varchar(255) NOT NULL," | ||
| " `special` tinyint(1) NOT NULL," | ||
| " `rank` int(11) NOT NULL," | ||
| " PRIMARY KEY (`id`)" | ||
| ") ENGINE = InnoDB DEFAULT CHARSET=latin1") | ||
| TABLES['post2tag'] = ( | ||
|
|
@@ -31,6 +31,48 @@ def createTables(): | |
| " `name` varchar(255) NOT NULL," | ||
| " PRIMARY KEY (`id`)" | ||
| ") ENGINE = InnoDB DEFAULT CHARSET=latin1") | ||
| TABLES['text'] = ( | ||
| "CREATE TABLE `text` (" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i suggest to rename table to 'post_content' |
||
| " `id` int(11) NOT NULL AUTO_INCREMENT," | ||
| " `p_text` longtext NOT NULL," | ||
| " PRIMARY KEY (`id`)" | ||
| ") ENGINE = InnoDB DEFAULT CHARSET=latin1") | ||
| TABLES['tag_query1'] = ( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. post_site1 or post_site_country1 |
||
| "CREATE TABLE `tag_query1` (" | ||
| " `text_id` int(11) NOT NULL AUTO_INCREMENT," | ||
| " `p_site` varchar(20) NOT NULL," | ||
| " `p_ES` tinyint(1) NOT NULL," | ||
| " `p_US` tinyint(1) NOT NULL," | ||
| " `p_MX` tinyint(1) NOT NULL," | ||
| " `p_CO` tinyint(1) NOT NULL," | ||
| " `p_published` timestamp NOT NULL," | ||
| " PRIMARY KEY (`id`)" | ||
| ") ENGINE = InnoDB DEFAULT CHARSET=latin1") | ||
| TABLES['tag_query2'] = ( | ||
| "CREATE TABLE `tag_query2` (" | ||
| " `text_id` int(11) NOT NULL AUTO_INCREMENT," | ||
| " `p_site` varchar(20) NOT NULL," | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. site |
||
| " `p_ES` tinyint(1) NOT NULL," | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ES
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
| " `p_US` tinyint(1) NOT NULL," | ||
| " `p_MX` tinyint(1) NOT NULL," | ||
| " `p_CO` tinyint(1) NOT NULL," | ||
| " `p_rank` int(11) NOT NULL," | ||
| " PRIMARY KEY (`id`)" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. text_id |
||
| ") ENGINE = InnoDB DEFAULT CHARSET=latin1") | ||
| TABLES['tag_query3'] = ( | ||
| "CREATE TABLE `tag_query3` (" | ||
| " `text_id` int(11) NOT NULL AUTO_INCREMENT," | ||
| " `p_site` varchar(20) NOT NULL," | ||
| " `p_ES` tinyint(1) NOT NULL," | ||
| " `p_US` tinyint(1) NOT NULL," | ||
| " `p_MX` tinyint(1) NOT NULL," | ||
| " `p_CO` tinyint(1) NOT NULL," | ||
| " `p_rank` int(11) NOT NULL," | ||
| " `p_published` timestamp NOT NULL," | ||
| " `p_type` enum('normal', 'ecommerce', 'slideshow', 'video', 'duplicate', 'branded_club', 'brand_article', 'brand_article_video', 'longform', 'reposted_slideshow') NOT NULL DEFAULT 'normal'," | ||
| " PRIMARY KEY (`id`)" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. text_id |
||
| ") ENGINE = InnoDB DEFAULT CHARSET=latin1") | ||
|
|
||
| for name, dbq in TABLES.items(): | ||
| try: | ||
| print("Creating table {}: ".format(name), end = '') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import pymysql.cursors | ||
| import config | ||
|
|
||
| def tagQueryPopulate(): | ||
| query = "INSERT tag_query1 (p_site, p_ES, p_US, p_MX, p_CO, p_published) SELECT site, ES, US, MX, CO, published FROM wp_posts ORDER BY id ASC" | ||
| cursor.execute(query) | ||
| connection.commit() | ||
| print("Table 1 Populated") | ||
| query = "INSERT tag_query2 (p_site, p_ES, p_US, p_MX, p_CO, p_rank) SELECT site, ES, US, MX, CO, rank FROM wp_posts ORDER BY id ASC" | ||
| cursor.execute(query) | ||
| connection.commit() | ||
| print("Table 2 Populated") | ||
| query = "INSERT tag_query3 (p_site, p_ES, p_US, p_MX, p_CO, p_rank, p_published, p_type) SELECT site, ES, US, MX, CO, rank, published, type FROM wp_posts ORDER BY id ASC" | ||
| cursor.execute(query) | ||
| connection.commit() | ||
| print("Table 3 Populated") | ||
| query = "INSERT text (p_text) SELECT text FROM wp_posts ORDER BY id ASC" | ||
| cursor.execute(query) | ||
| connection.commit() | ||
| print("Table 4 Populated") | ||
|
|
||
| def process(): | ||
| global connection, cursor | ||
| connection = pymysql.connect(**config.dbConfig) | ||
| cursor = connection.cursor() | ||
| print("=====================================================") | ||
| print("Populating Tag Query Tables") | ||
| tagQueryPopulate() | ||
| print("=====================================================") | ||
| cursor.close() | ||
| connection.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
counter