Skip to content

Commit

Permalink
Merge pull request #14 from Kalkuli/develop
Browse files Browse the repository at this point in the history
Release Final Sprint
  • Loading branch information
bernardohrl authored Nov 26, 2018
2 parents a14281e + 5882da1 commit d3c5d93
Show file tree
Hide file tree
Showing 17 changed files with 388 additions and 174 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: gunicorn -b 0.0.0.0:$PORT manage:app
release: python manage.py recreatedb
release: python manage.py db upgrade
63 changes: 55 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,35 @@

<div style="text-align: center">

<a href="https://travis-ci.com/Kalkuli/2018.2-Kalkuli_Reports"><img src="https://travis-ci.org/Kalkuli/2018.2-Kalkuli_Reports.svg?branch=master" /></a>
<a href="https://travis-ci.com/Kalkuli/2018.2-Kalkuli_Reports"><img src="https://travis-ci.com/Kalkuli/2018.2-Kalkuli_Reports.svg?branch=master" /></a>
<a href="https://codeclimate.com/github/Kalkuli/2018.2-Kalkuli_Reports/test_coverage"><img src="https://api.codeclimate.com/v1/badges/1f500530c8778423167f/test_coverage" /></a>
<a href="https://codeclimate.com/github/Kalkuli/2018.2-Kalkuli_Reports/maintainability"><img src="https://api.codeclimate.com/v1/badges/1f500530c8778423167f/maintainability" /></a>
<a href="https://opensource.org/licenses/GPL-3.0"><img src="https://img.shields.io/badge/license-GPL-%235DA8C1.svg"/></a>

</div>


## Deploy
## Ambientes

A ultima versão do app pode ser encontrada em: https://kalkuli-reports.herokuapp.com
### Produção
Para acessar o ambiente de produção utilize o link abaixo:
```https://kalkuli-reports.herokuapp.com/```

### Homologação
Para acessar o ambiente de homologação clique no link abaixo:
```https://kalkuli-reports-hom.herokuapp.com/```

***

<br>

## Configurando o ambiente
Para instruções de como instalar o Docker e o Docker-compose clique [aqui](https://github.com/Kalkuli/2018.2-Kalkuli_Front-End/blob/master/README.md).

***

<br>

## Colocando no ar
Com o _Docker_ e _Docker-Compose_ instalados, basta apenas utilizar os comandos:

Expand All @@ -32,21 +42,58 @@ docker-compose -f docker-compose-dev.yml build
docker-compose -f docker-compose-dev.yml up
```

Abra outro terminal, e execute o comando:
Acesse o servidor local no endereço apresentado abaixo:


[localhost:5004](http://localhost:5004/)

Agora você já pode começar a contribuir!

***

<br>

## Configurando o Banco de Dados Local

Agora iremos configurar o Banco de Dados da aplicação. Siga um dos dois passos a seguir.

* Caso seja a primeira vez utilizando o serviço, utilize os comandos abaixo para criar o banco e atualizá-lo:


```
docker-compose -f docker-compose-dev.yml run base python manage.py recreatedb
docker-compose -f docker-compose-dev.yml run base python manage.py db upgrade
```

Acesse o servidor local no endereço apresentado abaixo:
<br>

* Caso o banco já tenha sido criado localmente, e você deseja apenas atualizá-lo, utilize o seguite comando:

[localhost:5004](http://localhost:5004/)
```
docker-compose -f docker-compose-dev.yml run base python manage.py db upgrade
```

Agora você já pode começar a contribuir!
<br>

***
* Case tenha feito alguma alteração nas models, utilize os seguintes comando para manter o controle de versão do banco.

```
docker-compose -f docker-compose-dev.yml run base python manage.py db migrate
docker-compose -f docker-compose-dev.yml run base python manage.py db upgrade
```

<br>

* Para popular o Banco de Dados execute:
```
docker-compose -f docker-compose-dev.yml run base python manage.py seed
```

***

<br>

## Testando

Expand Down
15 changes: 11 additions & 4 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
from flask.cli import FlaskGroup
from project import app, db
from project.api.models import Report, TagUseReport
import unittest
import coverage

COV = coverage.coverage(
Expand All @@ -14,6 +10,12 @@
)
COV.start()

from flask.cli import FlaskGroup
from project import app, db
from project.api.models import Report
import unittest
from populate import seedReports

cli = FlaskGroup(app)


Expand All @@ -24,6 +26,11 @@ def recreatedb():
db.create_all()
db.session.commit()

#Populate Functions
@cli.command()
def seed():
seedReports(db)


# Registers comand to run tests
@cli.command()
Expand Down
1 change: 1 addition & 0 deletions migrations/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generic single-database configuration.
45 changes: 45 additions & 0 deletions migrations/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# A generic, single database configuration.

[alembic]
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false


# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
87 changes: 87 additions & 0 deletions migrations/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
import logging

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from flask import current_app
config.set_main_option('sqlalchemy.url',
current_app.config.get('SQLALCHEMY_DATABASE_URI'))
target_metadata = current_app.extensions['migrate'].db.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url)

with context.begin_transaction():
context.run_migrations()


def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""

# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')

engine = engine_from_config(config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)

connection = engine.connect()
context.configure(connection=connection,
target_metadata=target_metadata,
process_revision_directives=process_revision_directives,
**current_app.extensions['migrate'].configure_args)

try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()

if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
24 changes: 24 additions & 0 deletions migrations/script.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""${message}

Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}

"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}

# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}


def upgrade():
${upgrades if upgrades else "pass"}


def downgrade():
${downgrades if downgrades else "pass"}
28 changes: 28 additions & 0 deletions migrations/versions/5c8cb2dc53b9_.py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""empty message
Revision ID: 5c8cb2dc53b9
Revises: c4d7d15a174b
Create Date: 2018-11-18 23:54:49.043724
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '5c8cb2dc53b9'
down_revision = 'c4d7d15a174b'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('report', 'teste')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('report', sa.Column('teste', sa.VARCHAR(), autoincrement=False, nullable=True))
# ### end Alembic commands ###
28 changes: 28 additions & 0 deletions migrations/versions/c4d7d15a174b_.py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""empty message
Revision ID: c4d7d15a174b
Revises:
Create Date: 2018-11-18 23:54:10.005828
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'c4d7d15a174b'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('report', sa.Column('teste', sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('report', 'teste')
# ### end Alembic commands ###
8 changes: 8 additions & 0 deletions populate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from project.api.models import Report


def seedReports(db):
db.session.add(Report(company_id=1, date_from='2018-09-13', date_to='2018-09-21', total_cost='12.23', total_tax_cost=2.33))
db.session.add(Report(company_id=2, date_from='2018-10-15', date_to='2018-10-22', total_cost='122.23', total_tax_cost=10.53))
db.session.add(Report(company_id=3, date_from='2018-11-14', date_to='2018-11-23', total_cost='412.30', total_tax_cost=200.13))
db.session.commit()
2 changes: 2 additions & 0 deletions project/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from flask import Flask, jsonify
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

# Instantiate the app
app = Flask(__name__)
Expand All @@ -13,6 +14,7 @@

# Instanciate Database
db = SQLAlchemy(app)
migrate = Migrate(app, db)

from project.api.views import reports_blueprint

Expand Down
Loading

0 comments on commit d3c5d93

Please sign in to comment.