-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[server] Create columns for product details
Create separate columns for products to store the number of runs and the latest storage date instead of connecting and getting these information from each product database.
- Loading branch information
1 parent
5e57931
commit 81113ae
Showing
8 changed files
with
170 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...hecker_server/migrations/config/versions/4db450cf38af_add_extra_product_detail_columns.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Add columns for number of runs and latest run storage | ||
Revision ID: 4db450cf38af | ||
Revises: 302693c76eb8 | ||
Create Date: 2021-06-28 15:52:57.237509 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '4db450cf38af' | ||
down_revision = '302693c76eb8' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
from codechecker_common.logger import get_logger | ||
from codechecker_server.database import database | ||
from codechecker_server.database.run_db_model import IDENTIFIER as RUN_META | ||
from codechecker_web.shared import webserver_context | ||
|
||
LOG = get_logger('system') | ||
|
||
|
||
def upgrade(): | ||
op.add_column( | ||
'products', | ||
sa.Column( | ||
'latest_storage_date', | ||
sa.DateTime(), | ||
nullable=True)) | ||
|
||
op.add_column( | ||
'products', | ||
sa.Column( | ||
'num_of_runs', | ||
sa.Integer(), | ||
server_default="0", | ||
nullable=True)) | ||
|
||
try: | ||
product_con = op.get_bind() | ||
products = product_con.execute( | ||
"SELECT id, connection from products").fetchall() | ||
|
||
context = webserver_context.get_context() | ||
for id, connection in products: | ||
sql_server = database.SQLServer.from_connection_string( | ||
connection, RUN_META, context.run_migration_root) | ||
|
||
engine = sa.create_engine(sql_server.get_connection_string()) | ||
conn = engine.connect() | ||
|
||
run_info = \ | ||
conn.execute("SELECT count(*), max(date) from runs").fetchone() | ||
|
||
product_con.execute(f""" | ||
UPDATE products | ||
SET num_of_runs={run_info[0]}, | ||
latest_storage_date='{run_info[1]}' | ||
WHERE id={id} | ||
""") | ||
except: | ||
LOG.error("Failed to fill product detail columns (num_of_runs, " | ||
"latest_storage_date)!") | ||
pass | ||
|
||
def downgrade(): | ||
op.drop_column('products', 'num_of_runs') | ||
op.drop_column('products', 'latest_storage_date') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters