2

I am developing a project in Flask and using SQLAlchemy as ORM
I have a User model as

class User(UserMixin, db.Model):
    __tablename__ = 'users'
    # noinspection PyShadowingBuiltins
    uuid = Column('uuid', GUID(), default=uuid.uuid4, primary_key=True,
                  unique=True)
    email = Column('email', String, nullable=False, unique=True)
    _password = Column('password', String, nullable=False)
    created_on = Column('created_on', sa.types.DateTime(timezone=True),
                        default=datetime.utcnow())
    last_login = Column('last_login', sa.types.DateTime(timezone=True),
                        onupdate=datetime.utcnow())
  • I create a migration script using Alembic.
  • My database of choice is PostgreSQL but to test my models I preferred to use SQLite to make tests faster
  • Problem came in when there are some types in PostgreSQL and not in SQLite, in this case UUID
  • When I run migration on sqlite://, it gives me error

AttributeError: 'module' object has no attribute 'GUID'

Question
- How can I keep my schema with GUID and run in-memory tests with SQLite? seems like SQLite doesn't have anything like it
- What are some ways people run tests faster(in-memory) when their database is PostgreSQL

daydreamer
  • 87,243
  • 191
  • 450
  • 722
  • 2
    Generally speaking, it's not a good practice to mix database backends for testing, development and release. See similar questions: http://stackoverflow.com/questions/2716847/sqlalchemy-sqlite-for-testing-and-postgresql-for-development-how-to-port and http://stackoverflow.com/questions/2685899/schema-qualified-tables-with-sqlalchemy-sqlite-and-postgresql. – alecxe Mar 29 '13 at 13:05

1 Answers1

1

How comes the tests faster with SQLite?

Anyway, if you want to keep things in memory...well, so keep your database in memory. Actually PostgreSQL moves frequently accessed data to memory, but anyway, you can install some RAMFS/RAMHDD solution and put your database there, so it will be extremely fast

You can google for solutions "postgresql on ramdisk"

Tigra
  • 2,611
  • 20
  • 22