|
10 | 10 |
|
11 | 11 | #pylint: disable=line-too-long, too-many-lines, bad-whitespace |
12 | 12 |
|
13 | | -DB_VERSION = 24 |
| 13 | +DB_VERSION = 25 |
14 | 14 |
|
15 | 15 | def build_metadata(): |
16 | 16 | """Build schema def with SqlAlchemy""" |
@@ -247,8 +247,64 @@ def build_metadata(): |
247 | 247 |
|
248 | 248 | metadata = build_trxid_block_num(metadata) |
249 | 249 |
|
| 250 | + metadata = build_temp_cache_metadata(metadata) |
| 251 | + |
| 252 | + return metadata |
| 253 | + |
| 254 | + |
| 255 | +def build_temp_cache_metadata(metadata=None): |
| 256 | + """Build hive_posts_cache_temp table for hot-data queries (90-day window).""" |
| 257 | + if not metadata: |
| 258 | + metadata = sa.MetaData() |
| 259 | + |
| 260 | + sa.Table( |
| 261 | + 'hive_posts_cache_temp', metadata, |
| 262 | + sa.Column('post_id', sa.Integer, primary_key=True, autoincrement=False), |
| 263 | + sa.Column('author', VARCHAR(16), nullable=False), |
| 264 | + sa.Column('permlink', VARCHAR(255), nullable=False), |
| 265 | + sa.Column('category', VARCHAR(255), nullable=False, server_default=''), |
| 266 | + sa.Column('community_id', sa.Integer, nullable=True), |
| 267 | + sa.Column('depth', SMALLINT, nullable=False, server_default='0'), |
| 268 | + sa.Column('children', SMALLINT, nullable=False, server_default='0'), |
| 269 | + sa.Column('author_rep', sa.Float(precision=6), nullable=False, server_default='0'), |
| 270 | + sa.Column('flag_weight', sa.Float(precision=6), nullable=False, server_default='0'), |
| 271 | + sa.Column('total_votes', sa.Integer, nullable=False, server_default='0'), |
| 272 | + sa.Column('up_votes', sa.Integer, nullable=False, server_default='0'), |
| 273 | + sa.Column('title', sa.String(255), nullable=False, server_default=''), |
| 274 | + sa.Column('preview', sa.String(1024), nullable=False, server_default=''), |
| 275 | + sa.Column('img_url', sa.String(1024), nullable=False, server_default=''), |
| 276 | + sa.Column('payout', sa.types.DECIMAL(10, 3), nullable=False, server_default='0'), |
| 277 | + sa.Column('promoted', sa.types.DECIMAL(10, 3), nullable=False, server_default='0'), |
| 278 | + sa.Column('created_at', sa.DateTime, nullable=False, server_default='1990-01-01'), |
| 279 | + sa.Column('payout_at', sa.DateTime, nullable=False, server_default='1990-01-01'), |
| 280 | + sa.Column('updated_at', sa.DateTime, nullable=False, server_default='1990-01-01'), |
| 281 | + sa.Column('is_paidout', BOOLEAN, nullable=False, server_default='0'), |
| 282 | + sa.Column('is_nsfw', BOOLEAN, nullable=False, server_default='0'), |
| 283 | + sa.Column('is_declined', BOOLEAN, nullable=False, server_default='0'), |
| 284 | + sa.Column('is_full_power', BOOLEAN, nullable=False, server_default='0'), |
| 285 | + sa.Column('is_hidden', BOOLEAN, nullable=False, server_default='0'), |
| 286 | + sa.Column('is_grayed', BOOLEAN, nullable=False, server_default='0'), |
| 287 | + sa.Column('rshares', sa.BigInteger, nullable=False, server_default='0'), |
| 288 | + sa.Column('sc_trend', sa.Float(precision=6), nullable=False, server_default='0'), |
| 289 | + sa.Column('sc_hot', sa.Float(precision=6), nullable=False, server_default='0'), |
| 290 | + sa.Column('body', TEXT), |
| 291 | + sa.Column('votes', TEXT), |
| 292 | + sa.Column('json', sa.Text), |
| 293 | + sa.Column('raw_json', sa.Text), |
| 294 | + sa.Column('_synced_at', sa.DateTime, nullable=True), |
| 295 | + sa.Index('hive_posts_cache_temp_ix6a', 'sc_trend', 'post_id', |
| 296 | + postgresql_where=sql_text("is_paidout = '0'")), |
| 297 | + sa.Index('hive_posts_cache_temp_ix7a', 'sc_hot', 'post_id', |
| 298 | + postgresql_where=sql_text("is_paidout = '0'")), |
| 299 | + sa.Index('hive_posts_cache_temp_ix9a', 'depth', 'payout', 'post_id', |
| 300 | + postgresql_where=sql_text("is_paidout = '0'")), |
| 301 | + sa.Index('hive_posts_cache_temp_ix30', 'community_id', 'sc_trend', 'post_id', |
| 302 | + postgresql_where=sql_text("community_id IS NOT NULL AND is_grayed = '0' AND depth = 0")), |
| 303 | + sa.Index('hive_posts_cache_temp_created', 'created_at'), |
| 304 | + ) |
250 | 305 | return metadata |
251 | 306 |
|
| 307 | + |
252 | 308 | def build_metadata_community(metadata=None): |
253 | 309 | """Build community schema defs""" |
254 | 310 | if not metadata: |
|
0 commit comments