diff --git a/api/public/public_api/endpoints/device_subscription.py b/api/public/public_api/endpoints/device_subscription.py index 286bcb99..d38482e5 100644 --- a/api/public/public_api/endpoints/device_subscription.py +++ b/api/public/public_api/endpoints/device_subscription.py @@ -13,8 +13,8 @@ class DeviceSubscriptionEndpoint(SeleneEndpoint): with get_db_connection(self.config['DB_CONNECTION_POOL']) as db: account = AccountRepository(db).get_account_by_device_id(device_id) if account: - subscription = account.subscription - response = {'@type': subscription.type if subscription is not None else 'free'}, HTTPStatus.OK + membership = account.membership + response = {'@type': membership.type if membership is not None else 'free'}, HTTPStatus.OK else: response = '', HTTPStatus.NO_CONTENT return response diff --git a/api/public/tests/features/environment.py b/api/public/tests/features/environment.py index 9f977777..f38290e4 100644 --- a/api/public/tests/features/environment.py +++ b/api/public/tests/features/environment.py @@ -24,7 +24,7 @@ account = Account( AccountAgreement(type=PRIVACY_POLICY, accept_date=date.today()), AccountAgreement(type=TERMS_OF_USE, accept_date=date.today()) ], - subscription=None + membership=None ) wake_word = WakeWord( diff --git a/api/public/tests/features/steps/get_device_subscription.py b/api/public/tests/features/steps/get_device_subscription.py index 059c820f..56f912e2 100644 --- a/api/public/tests/features/steps/get_device_subscription.py +++ b/api/public/tests/features/steps/get_device_subscription.py @@ -6,7 +6,7 @@ from http import HTTPStatus from behave import when, then from hamcrest import assert_that, has_entry, equal_to -from selene.data.account import AccountRepository, AccountSubscription +from selene.data.account import AccountRepository, AccountMembership from selene.util.db import get_db_connection @@ -25,9 +25,9 @@ def validate_response(context): @when('the subscription endpoint is called for a monthly account') def get_device_subscription(context): - membership = AccountSubscription(start_date=date.today(), type='Monthly Supporter', stripe_customer_id='test_monthly') + membership = AccountMembership(start_date=date.today(), type='Monthly Supporter', stripe_customer_id='test_monthly') with get_db_connection(context.client_config['DB_CONNECTION_POOL']) as db: - AccountRepository(db).add_membership(context.account.id, membership) + AccountRepository(db)._add_membership(context.account.id, membership) context.subscription_response = context.client.get('/device/{uuid}/subscription'.format(uuid=context.device_id)) diff --git a/db/scripts/bootstrap_mycroft_db.py b/db/scripts/bootstrap_mycroft_db.py index 803ae641..21e03e0a 100644 --- a/db/scripts/bootstrap_mycroft_db.py +++ b/db/scripts/bootstrap_mycroft_db.py @@ -146,7 +146,8 @@ for schema in SCHEMAS: template_db.close_db() print('Copying template to new database.') -postgres_db = PostgresDB(dbname='postgres', user='chrisveilleux') +# Copy template to new database. +postgres_db = PostgresDB(dbname='postgres', user='postgres') postgres_db.execute_sql(get_sql_from_file('create_mycroft_db.sql')) postgres_db.close_db() diff --git a/db/scripts/neo4j-postgres.py b/db/scripts/neo4j-postgres.py index 4484b96c..880a0939 100644 --- a/db/scripts/neo4j-postgres.py +++ b/db/scripts/neo4j-postgres.py @@ -446,7 +446,7 @@ end = time.time() print('Time to load CSVs {}'.format(end - start)) print('Importing the skills table') -""" + start = time.time() print('Importing account table') fill_account_table() @@ -463,6 +463,5 @@ fill_device_category_table() print('Importing device table') fill_device_table() fill_skills_table() -""" end = time.time() print('Time to import: {}'.format(end-start)) diff --git a/shared/selene/data/account/repository/sql/get_account_by_device_id.sql b/shared/selene/data/account/repository/sql/get_account_by_device_id.sql index 0a725dd1..4c16c66f 100644 --- a/shared/selene/data/account/repository/sql/get_account_by_device_id.sql +++ b/shared/selene/data/account/repository/sql/get_account_by_device_id.sql @@ -31,32 +31,32 @@ WITH WHERE dev.id = %(device_id)s ), - subscription AS ( + membership AS ( SELECT json_build_object( - 'id', asub.id, - 'type', s.subscription, - 'start_date', lower(asub.subscription_ts_range)::DATE, - 'stripe_customer_id', asub.stripe_customer_id + 'id', acc_mem.id, + 'type', mem.type, + 'start_date', lower(acc_mem.membership_ts_range)::DATE, + 'stripe_customer_id', acc_mem.stripe_customer_id ) FROM - account.account_subscription asub + account.account_membership acc_mem INNER JOIN - account.subscription s ON asub.subscription_id = s.id + account.membership mem ON acc_mem.membership_id = mem.id INNER JOIN - account.account acc ON asub.account_id = acc.id + account.account acc ON acc_mem.account_id = acc.id INNER JOIN device.device dev ON acc.id = dev.account_id WHERE dev.id = %(device_id)s - AND upper(asub.subscription_ts_range) IS NULL + AND upper(acc_mem.membership_ts_range) IS NULL ) SELECT json_build_object( 'id', acc.id, 'email_address', acc.email_address, 'username', acc.username, - 'subscription', (SELECT * FROM subscription), + 'membership', (SELECT * FROM membership), 'refresh_tokens', (SELECT * FROM refresh_tokens), 'agreements', (SELECT * FROM agreements) ) as account