mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-15 12:50:47 +02:00
Make fields nullable false in models (#456)
This commit is contained in:
parent
2f4ad44a44
commit
4e17c4611d
11 changed files with 28 additions and 141 deletions
|
|
@ -1,8 +1,8 @@
|
|||
"""Initialize all
|
||||
|
||||
Revision ID: ccc641c2ce52
|
||||
Revision ID: 024b6d0f4407
|
||||
Revises:
|
||||
Create Date: 2020-11-10 23:45:44.333190
|
||||
Create Date: 2020-11-12 23:33:57.135895
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
|
|
@ -10,7 +10,7 @@ import sqlalchemy as sa
|
|||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'ccc641c2ce52'
|
||||
revision = '024b6d0f4407'
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
|
@ -57,6 +57,25 @@ def upgrade():
|
|||
sa.UniqueConstraint('address'),
|
||||
sa.UniqueConstraint('profile_name')
|
||||
)
|
||||
op.create_table('received_payment',
|
||||
sa.Column('received_payment_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('squeak_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('preimage_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('price_msat', sa.Integer(), nullable=False),
|
||||
sa.Column('settle_index', sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('received_payment_id'),
|
||||
sa.UniqueConstraint('preimage_hash')
|
||||
)
|
||||
op.create_table('sent_offer',
|
||||
sa.Column('sent_offer_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('squeak_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('preimage_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('price_msat', sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('sent_offer_id'),
|
||||
sa.UniqueConstraint('preimage_hash')
|
||||
)
|
||||
op.create_table('sent_payment',
|
||||
sa.Column('sent_payment_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
|
|
@ -96,6 +115,8 @@ def downgrade():
|
|||
|
||||
op.drop_table('squeak')
|
||||
op.drop_table('sent_payment')
|
||||
op.drop_table('sent_offer')
|
||||
op.drop_table('received_payment')
|
||||
op.drop_table('profile')
|
||||
op.drop_table('peer')
|
||||
op.drop_table('offer')
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
"""Add received payments table
|
||||
|
||||
Revision ID: 31b943126c13
|
||||
Revises: dc185d885f13
|
||||
Create Date: 2020-11-12 01:29:19.946046
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '31b943126c13'
|
||||
down_revision = 'dc185d885f13'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('received_payment',
|
||||
sa.Column('received_payment_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('squeak_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('preimage_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('price_msat', sa.Integer(), nullable=False),
|
||||
sa.Column('settle_index', sa.Integer(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('received_payment_id'),
|
||||
sa.UniqueConstraint('preimage_hash')
|
||||
)
|
||||
with op.batch_alter_table('sent_offer', schema=None) as batch_op:
|
||||
batch_op.drop_column('settle_index')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('sent_offer', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('settle_index', sa.INTEGER(), nullable=True))
|
||||
|
||||
op.drop_table('received_payment')
|
||||
# ### end Alembic commands ###
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
"""Add sent_offer table
|
||||
|
||||
Revision ID: 387dd872e766
|
||||
Revises: ccc641c2ce52
|
||||
Create Date: 2020-11-11 01:24:10.148710
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '387dd872e766'
|
||||
down_revision = 'ccc641c2ce52'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('sent_offer',
|
||||
sa.Column('sent_offer_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('squeak_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('preimage_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('price_msat', sa.Integer(), nullable=False),
|
||||
sa.Column('is_paid', sa.Boolean(), nullable=False),
|
||||
sa.Column('payment_time', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('sent_offer_id'),
|
||||
sa.UniqueConstraint('preimage_hash')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('sent_offer')
|
||||
# ### end Alembic commands ###
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
"""Add settle_index to received payments table
|
||||
|
||||
Revision ID: dc185d885f13
|
||||
Revises: 387dd872e766
|
||||
Create Date: 2020-11-11 19:20:48.069164
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'dc185d885f13'
|
||||
down_revision = '387dd872e766'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('sent_offer', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('settle_index', sa.Integer(), nullable=True))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('sent_offer', schema=None) as batch_op:
|
||||
batch_op.drop_column('settle_index')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
|
@ -907,11 +907,6 @@ def test_connect_other_node(server_stub, admin_stub, other_server_stub, other_ad
|
|||
)
|
||||
assert saved_squeak_hash == get_sent_payment_response.sent_payment.squeak_hash
|
||||
assert get_sent_payment_response.sent_payment.price_msat == 1000000
|
||||
sent_payment_time_ms = get_sent_payment_response.sent_payment.time_ms
|
||||
sent_payment_time = datetime.datetime.fromtimestamp(sent_payment_time_ms/1000.0)
|
||||
five_minutes = datetime.timedelta(minutes=5)
|
||||
assert sent_payment_time > datetime.datetime.now() - five_minutes
|
||||
assert sent_payment_time < datetime.datetime.now()
|
||||
|
||||
# Get the sent offers from the seller node
|
||||
get_sent_offers_response = admin_stub.GetSentOffers(
|
||||
|
|
@ -936,6 +931,7 @@ def test_connect_other_node(server_stub, admin_stub, other_server_stub, other_ad
|
|||
received_payment_time_ms = received_payment.payment_time_ms
|
||||
print("received_payment_time_ms: {}".format(received_payment_time_ms))
|
||||
received_payment_time = datetime.datetime.fromtimestamp(received_payment_time_ms/1000.0)
|
||||
five_minutes = datetime.timedelta(minutes=5)
|
||||
assert received_payment_time > datetime.datetime.now() - five_minutes
|
||||
assert received_payment_time < datetime.datetime.now()
|
||||
|
||||
|
|
|
|||
|
|
@ -674,12 +674,6 @@ message SentOffer {
|
|||
|
||||
/// The price_msat
|
||||
int64 price_msat = 4;
|
||||
|
||||
/// Is the payment paid
|
||||
bool is_paid = 5;
|
||||
|
||||
/// Time of payment
|
||||
int64 payment_time_ms = 6;
|
||||
}
|
||||
|
||||
message GetReceivedPaymentsRequest {
|
||||
|
|
|
|||
|
|
@ -134,10 +134,6 @@ def sent_offer_to_message(sent_offer):
|
|||
squeak_hash=sent_offer.squeak_hash,
|
||||
preimage_hash=sent_offer.preimage_hash,
|
||||
price_msat=sent_offer.price_msat,
|
||||
is_paid=sent_offer.is_paid,
|
||||
payment_time_ms=int(sent_offer.payment_time.timestamp()) * 1000
|
||||
if sent_offer.payment_time
|
||||
else None,
|
||||
)
|
||||
|
||||
def received_payments_to_message(received_payment):
|
||||
|
|
|
|||
|
|
@ -117,8 +117,6 @@ class Models:
|
|||
Column("squeak_hash", String(64), nullable=False),
|
||||
Column("preimage_hash", String(64), unique=True, nullable=False),
|
||||
Column("price_msat", Integer, nullable=False, default=0),
|
||||
Column("is_paid", Boolean, nullable=False),
|
||||
Column("payment_time", DateTime, nullable=True),
|
||||
)
|
||||
|
||||
self.received_payments = Table(
|
||||
|
|
@ -128,6 +126,6 @@ class Models:
|
|||
Column("created", DateTime, server_default=func.now(), nullable=False),
|
||||
Column("squeak_hash", String(64), nullable=False),
|
||||
Column("preimage_hash", String(64), unique=True, nullable=False),
|
||||
Column("price_msat", Integer, nullable=False, default=0),
|
||||
Column("settle_index", Integer, nullable=True),
|
||||
Column("price_msat", Integer, nullable=False),
|
||||
Column("settle_index", Integer, nullable=False),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -943,7 +943,6 @@ class SqueakDb:
|
|||
squeak_hash=sent_offer.squeak_hash,
|
||||
preimage_hash=sent_offer.preimage_hash,
|
||||
price_msat=sent_offer.price_msat,
|
||||
is_paid=sent_offer.is_paid,
|
||||
)
|
||||
with self.get_connection() as connection:
|
||||
res = connection.execute(ins)
|
||||
|
|
@ -1151,8 +1150,6 @@ class SqueakDb:
|
|||
squeak_hash=row["squeak_hash"],
|
||||
preimage_hash=row["preimage_hash"],
|
||||
price_msat=row["price_msat"],
|
||||
is_paid=row["is_paid"],
|
||||
payment_time=row["payment_time"],
|
||||
)
|
||||
|
||||
def _parse_received_payment(self, row):
|
||||
|
|
|
|||
|
|
@ -149,8 +149,6 @@ class SqueakNode:
|
|||
squeak_hash=squeak_hash,
|
||||
preimage_hash=preimage_hash.hex(),
|
||||
price_msat=self.price_msat,
|
||||
is_paid=False,
|
||||
payment_time=None,
|
||||
)
|
||||
)
|
||||
# Return the buy offer
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@ from collections import namedtuple
|
|||
|
||||
SentOffer = namedtuple(
|
||||
"SentOffer",
|
||||
"sent_offer_id, squeak_hash, preimage_hash, price_msat, is_paid, payment_time",
|
||||
"sent_offer_id, squeak_hash, preimage_hash, price_msat",
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue