Change id column in LogEntry to a BigInt and migrate back to using that table
This commit is contained in:
parent
5e4d52f1fd
commit
7325b22c90
8 changed files with 56 additions and 22 deletions
|
@ -987,6 +987,7 @@ class LogEntryKind(BaseModel):
|
|||
|
||||
|
||||
class LogEntry(BaseModel):
|
||||
id = BigAutoField()
|
||||
kind = ForeignKeyField(LogEntryKind)
|
||||
account = IntegerField(index=True, column_name='account_id')
|
||||
performer = IntegerField(index=True, null=True, column_name='performer_id')
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
"""Change LogEntry to use a BigInteger as its primary key
|
||||
|
||||
Revision ID: 6c21e2cfb8b6
|
||||
Revises: d17c695859ea
|
||||
Create Date: 2018-07-27 16:30:02.877346
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '6c21e2cfb8b6'
|
||||
down_revision = 'd17c695859ea'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade(tables, tester):
|
||||
op.alter_column(
|
||||
table_name='logentry',
|
||||
column_name='id',
|
||||
nullable=False,
|
||||
autoincrement=True,
|
||||
type_=sa.BigInteger(),
|
||||
)
|
||||
|
||||
def downgrade(tables, tester):
|
||||
op.alter_column(
|
||||
table_name='logentry',
|
||||
column_name='id',
|
||||
nullable=False,
|
||||
autoincrement=True,
|
||||
type_=sa.Integer(),
|
||||
)
|
|
@ -7,7 +7,7 @@ from datetime import datetime, timedelta
|
|||
from cachetools import lru_cache
|
||||
|
||||
import data
|
||||
from data.database import LogEntry, LogEntry2, LogEntryKind, User, RepositoryActionCount, db
|
||||
from data.database import LogEntry, LogEntryKind, User, RepositoryActionCount, db
|
||||
from data.model import config, user, DataModelException
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -101,7 +101,7 @@ def _json_serialize(obj):
|
|||
|
||||
def log_action(kind_name, user_or_organization_name, performer=None, repository=None, ip=None,
|
||||
metadata={}, timestamp=None):
|
||||
""" Logs an entry in the LogEntry2 table. """
|
||||
""" Logs an entry in the LogEntry table. """
|
||||
if not timestamp:
|
||||
timestamp = datetime.today()
|
||||
|
||||
|
@ -132,7 +132,7 @@ def log_action(kind_name, user_or_organization_name, performer=None, repository=
|
|||
}
|
||||
|
||||
try:
|
||||
LogEntry2.create(**log_data)
|
||||
LogEntry.create(**log_data)
|
||||
except PeeweeException as ex:
|
||||
strict_logging_disabled = config.app_config.get('ALLOW_PULLS_WITHOUT_STRICT_LOGGING')
|
||||
if strict_logging_disabled and kind_name in ACTIONS_ALLOWED_WITHOUT_AUDIT_LOGGING:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from data.database import LogEntry, LogEntry2, User
|
||||
from data.database import LogEntry, User
|
||||
from data.model import config as _config
|
||||
from data.model.log import log_action
|
||||
|
||||
|
@ -21,8 +21,8 @@ def logentry_kind():
|
|||
|
||||
@pytest.fixture()
|
||||
def logentry(logentry_kind):
|
||||
with patch('data.database.LogEntry2.create', spec=True):
|
||||
yield LogEntry2
|
||||
with patch('data.database.LogEntry.create', spec=True):
|
||||
yield LogEntry
|
||||
|
||||
@pytest.fixture()
|
||||
def user():
|
||||
|
|
Reference in a new issue