Commit eb448b61 authored by Lukáš Lalinský's avatar Lukáš Lalinský

Add meta.created

parent 495def36
......@@ -3,6 +3,7 @@
import logging
from typing import Dict, Any, Iterable, List
from sqlalchemy import sql
from acoustid import tables as schema
from acoustid.db import FingerprintDB
......@@ -11,7 +12,7 @@ logger = logging.getLogger(__name__)
def insert_meta(conn, values):
# type: (FingerprintDB, Dict[str, Any]) -> int
insert_stmt = schema.meta.insert().values(**values)
insert_stmt = schema.meta.insert().values(created=sql.func.current_timestamp(), **values)
id = conn.execute(insert_stmt).inserted_primary_key[0]
logger.debug("Inserted meta %d with values %r", id, values)
return id
......
......@@ -31,7 +31,11 @@ def find_or_insert_source(conn, application_id, account_id, version=None):
schema.source.c.version == version))
id = conn.execute(query).scalar()
if id is None:
insert_stmt = schema.source.insert().values(account_id=account_id, application_id=application_id, version=version)
insert_stmt = schema.source.insert().values(
account_id=account_id,
application_id=application_id,
version=version,
)
id = conn.execute(insert_stmt).inserted_primary_key[0]
logger.info("Inserted source %d with account %d and application %d (%s)", id, account_id, application_id, version)
return id
......@@ -199,6 +199,8 @@ meta = Table('meta', metadata,
Column('track_no', Integer),
Column('disc_no', Integer),
Column('year', Integer),
# Column('created', DateTime(timezone=True), server_default=sql.func.current_timestamp(), nullable=False),
Column('created', DateTime(timezone=True)),
info={'bind_key': 'fingerprint'},
)
......
"""add meta.created
Revision ID: d2176bc400c8
Revises: 661fce6a2f64
Create Date: 2019-12-02 07:14:01.145411
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'd2176bc400c8'
down_revision = '661fce6a2f64'
branch_labels = None
depends_on = None
def upgrade(engine_name):
globals()["upgrade_%s" % engine_name]()
def downgrade(engine_name):
globals()["downgrade_%s" % engine_name]()
def upgrade_app():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
def downgrade_app():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
def upgrade_ingest():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
def downgrade_ingest():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
def upgrade_fingerprint():
op.add_column(u'meta', sa.Column('created', sa.DateTime(timezone=True), nullable=True))
def downgrade_fingerprint():
op.drop_column(u'meta', 'created')
......@@ -521,7 +521,7 @@ def test_submit_handler_with_meta(ctx):
submission = ctx.db.get_ingest_db().execute(query).fetchone()
assert_equals('b9c05616-1874-4d5d-b30e-6b959c922d28', submission['mbid'])
assert_equals(3, submission['meta_id'])
row = ctx.db.get_ingest_db().execute("SELECT * FROM meta WHERE id=%s", submission['meta_id']).fetchone()
row = dict(ctx.db.get_ingest_db().execute("SELECT * FROM meta WHERE id=%s", submission['meta_id']).fetchone())
expected = {
'id': submission['meta_id'],
'track': 'Voodoo People',
......@@ -532,7 +532,9 @@ def test_submit_handler_with_meta(ctx):
'disc_no': 3,
'year': 2030
}
assert_equals(expected, dict(row))
assert row['created'] is not None
del row['created']
assert_equals(expected, row)
@with_script_context
......
......@@ -20,7 +20,7 @@ def test_insert_meta(ctx):
'year': 2030
})
assert_equals(3, meta_id)
row = ctx.db.get_fingerprint_db().execute("SELECT * FROM meta WHERE id=%s", meta_id).fetchone()
row = dict(ctx.db.get_fingerprint_db().execute("SELECT * FROM meta WHERE id=%s", meta_id).fetchone())
expected = {
'id': meta_id,
'track': 'Voodoo People',
......@@ -31,4 +31,6 @@ def test_insert_meta(ctx):
'disc_no': 3,
'year': 2030
}
assert_equals(expected, dict(row))
assert row['created'] is not None
del row['created']
assert_equals(expected, row)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment