Skip to content

Commit

Permalink
m0ngr31#32 Add mysql and pgsql database support
Browse files Browse the repository at this point in the history
  • Loading branch information
ctx-chend committed May 10, 2021
1 parent 2df0517 commit 343e0a9
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WORKDIR /app

COPY . .

RUN apk add build-base libffi-dev
RUN apk add build-base libffi-dev postgresql-dev

RUN \
cd /app && \
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ The recommended way of running is to pull the image from [Docker Hub](https://hu
|---|---|
| /app/config | Used to store DB and environment variables. This is not needed if you pass in all of the above environment variables. |

#### Database setup
**MySQL**
Set DATABASE_URI connect string as `mysql+pymysql://user:pass@some_mariadb/dbname?charset=utf8mb4`


**PostgreSQL**
Set DATABASE_URI connect string as `postgresql+psycopg2://user:pass@host/dbname?client_encoding=utf8`


#### Docker Run
By default, the easiest way to get running is:
Expand Down
8 changes: 4 additions & 4 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class Meta(db.Model):
uuid = db.Column(GUID, primary_key=True, index=True, unique=True, default=lambda: uuid.uuid4())
user_id = db.Column(GUID, db.ForeignKey('user.uuid'), nullable=False)
note_id = db.Column(GUID, db.ForeignKey('note.uuid'), nullable=False)
name_encrypted = db.Column('name', db.String)
name_compare = db.Column(db.String)
kind = db.Column(db.String)
name_encrypted = db.Column('name', db.String(512))
name_compare = db.Column(db.String(512))
kind = db.Column(db.String(128))

@hybrid_property
def name(self):
Expand All @@ -90,7 +90,7 @@ def serialize(self):
class Note(db.Model):
uuid = db.Column(GUID, primary_key=True, index=True, unique=True, default=lambda: uuid.uuid4())
user_id = db.Column(GUID, db.ForeignKey('user.uuid'), nullable=False)
data = db.Column(db.String)
data = db.Column(db.Text())
title = db.Column(db.String(128), nullable=False)
date = db.Column(db.DateTime(timezone=True), server_default=func.now())
is_date = db.Column(db.Boolean, default=False)
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ services:
- ./dailynotes-volume:/app/config
environment:
API_SECRET_KEY: CHANGE_THIS_WITH_SECURE_PASSWORD
DB_ENCRYPTION_KEY: CHANGE_THIS_WITH_SECURE_PASSWORD
DB_ENCRYPTION_KEY: CHANGE_THIS_WITH_SECURE_PASSWORD
DATABASE_URI: CHANGE_THIS_WITH_YOUR_DATABASE_URL, OR REMOVE IT IF YOU USE SQLITE
6 changes: 3 additions & 3 deletions migrations/versions/7bd1ee1840ca_meta_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def upgrade():
sa.Column('uuid', app.model_types.GUID(), nullable=False),
sa.Column('user_id', app.model_types.GUID(), nullable=False),
sa.Column('note_id', app.model_types.GUID(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('name_compare', sa.String(), nullable=True),
sa.Column('kind', sa.String(), nullable=True),
sa.Column('name', sa.String(128), nullable=True),
sa.Column('name_compare', sa.String(512), nullable=True),
sa.Column('kind', sa.String(128), nullable=True),
sa.ForeignKeyConstraint(['note_id'], ['note.uuid'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.uuid'], ),
sa.PrimaryKeyConstraint('uuid')
Expand Down
4 changes: 2 additions & 2 deletions migrations/versions/9ca5901af374_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def upgrade():
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('note', schema=None) as batch_op:
batch_op.add_column(sa.Column('tags', sa.VARCHAR(), nullable=True))
batch_op.add_column(sa.Column('projects', sa.VARCHAR(), nullable=True))
batch_op.add_column(sa.Column('tags', sa.VARCHAR(128), nullable=True))
batch_op.add_column(sa.Column('projects', sa.VARCHAR(128), nullable=True))

# ### end Alembic commands ###
6 changes: 3 additions & 3 deletions migrations/versions/a477f34dbaa4_initial_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def upgrade():
op.create_index(op.f('ix_user_uuid'), 'user', ['uuid'], unique=True)
op.create_table('note',
sa.Column('uuid', app.model_types.GUID(), nullable=False),
sa.Column('tags', sa.String(), nullable=True),
sa.Column('projects', sa.String(), nullable=True),
sa.Column('tags', sa.String(128), nullable=True),
sa.Column('projects', sa.String(128), nullable=True),
sa.Column('user_id', app.model_types.GUID(), nullable=False),
sa.Column('data', sa.String(), nullable=True),
sa.Column('data', sa.Text(), nullable=True),
sa.Column('title', sa.String(length=128), nullable=False),
sa.Column('date', sa.DateTime(timezone=True), server_default=sa.text(u'(CURRENT_TIMESTAMP)'), nullable=True),
sa.Column('is_date', sa.Boolean(), nullable=True),
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ flask-migrate
flask-jwt-extended
flask-argon2
python-frontmatter
pycrypto
pycrypto
PyMySQL
psycopg2-binary

0 comments on commit 343e0a9

Please sign in to comment.