Initial version; basic list + member tables, import from MailChimp API

This commit is contained in:
Lance Edgar 2021-11-08 13:26:23 -06:00
commit 8d858d74bd
17 changed files with 1366 additions and 0 deletions

View file

View file

@ -0,0 +1,57 @@
# -*- coding: utf-8; -*-
"""initial tables
Revision ID: 805181d09df7
Revises: 8856f697902d
Create Date: 2021-11-07 21:17:31.196005
"""
from __future__ import unicode_literals, absolute_import
# revision identifiers, used by Alembic.
revision = '805181d09df7'
down_revision = None
branch_labels = ('rattail_mailchimp',)
depends_on = None
from alembic import op
import sqlalchemy as sa
import rattail.db.types
def upgrade():
# mailchimp_list
op.create_table('mailchimp_list',
sa.Column('uuid', sa.String(length=32), nullable=False),
sa.Column('id', sa.String(length=100), nullable=True),
sa.Column('name', sa.String(length=100), nullable=True),
sa.Column('date_created', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('uuid')
)
# mailchimp_list_member
op.create_table('mailchimp_list_member',
sa.Column('uuid', sa.String(length=32), nullable=False),
sa.Column('list_uuid', sa.String(length=32), nullable=False),
sa.Column('id', sa.String(length=32), nullable=True),
sa.Column('email_address', sa.String(length=255), nullable=True),
sa.Column('contact_id', sa.String(length=50), nullable=True),
sa.Column('full_name', sa.String(length=100), nullable=True),
sa.Column('email_type', sa.String(length=10), nullable=True),
sa.Column('status', sa.String(length=20), nullable=True),
sa.Column('unsubscribe_reason', sa.Text(), nullable=True),
sa.Column('last_changed', sa.DateTime(), nullable=True),
sa.Column('source', sa.String(length=255), nullable=True),
sa.ForeignKeyConstraint(['list_uuid'], ['mailchimp_list.uuid'], name='mailchimp_list_member_fk_list'),
sa.PrimaryKeyConstraint('uuid')
)
def downgrade():
# mailchimp_list*
op.drop_table('mailchimp_list_member')
op.drop_table('mailchimp_list')

View file

@ -0,0 +1,86 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2021 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Database schema extensions for Mailchimp integration
"""
import sqlalchemy as sa
from sqlalchemy import orm
from rattail.db import model
class MailChimpList(model.Base):
"""
List record cache for MailChimp.
"""
__tablename__ = 'mailchimp_list'
model_title = "MailChimp List"
uuid = model.uuid_column()
id = sa.Column(sa.String(length=100), nullable=True)
name = sa.Column(sa.String(length=100), nullable=True)
date_created = sa.Column(sa.DateTime(), nullable=True)
def __str__(self):
return self.name or ""
class MailChimpListMember(model.Base):
"""
ListMember record cache for MailChimp.
"""
__tablename__ = 'mailchimp_list_member'
__table_args__ = (
sa.ForeignKeyConstraint(['list_uuid'], ['mailchimp_list.uuid'],
name='mailchimp_list_member_fk_list'),
)
uuid = model.uuid_column()
list_uuid = sa.Column(sa.String(length=32), nullable=False)
list = orm.relationship(MailChimpList, backref='members')
id = sa.Column(sa.String(length=32), nullable=True)
email_address = sa.Column(sa.String(length=255), nullable=True)
contact_id = sa.Column(sa.String(length=50), nullable=True)
full_name = sa.Column(sa.String(length=100), nullable=True)
email_type = sa.Column(sa.String(length=10), nullable=True)
status = sa.Column(sa.String(length=20), nullable=True)
unsubscribe_reason = sa.Column(sa.Text(), nullable=True)
last_changed = sa.Column(sa.DateTime(), nullable=True)
source = sa.Column(sa.String(length=255), nullable=True)
def __str__(self):
return self.email_address or ""