Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The types of changes are:
* `Security` in case of vulnerabilities.


## [Unreleased](https://github.com/ethyca/fidesops/compare/1.5.2...main)
## [Unreleased](https://github.com/ethyca/fidesops/compare/1.5.3...main)

### Added
* Subject Request Details page [#563](https://github.com/ethyca/fidesops/pull/563)
Expand All @@ -29,6 +29,14 @@ The types of changes are:

* Refactor auth and enable static file serving [#577](https://github.com/ethyca/fidesops/pull/577)

## [1.5.3](https://github.com/ethyca/fidesops/compare/1.5.2...1.5.3)

### Changed
* Database migrations now exist as part of the core `fidesops` package [#620](https://github.com/ethyca/fidesops/pull/620)

### Removed
* The `[package]` config section no longer exists [#620](https://github.com/ethyca/fidesops/pull/620)

## [1.5.2](https://github.com/ethyca/fidesops/compare/1.5.1...1.5.2)

### Added
Expand Down
8 changes: 4 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ include README.md
include requirements.txt
include dev-requirements.txt
include versioneer.py
include src/alembic.ini
include src/fidesops/alembic.ini
include src/fidesops/_version.py
graft src/migrations
exclude src/migrations/README
exclude src/migrations/script.py.mako
graft src/fidesops/migrations
exclude src/fidesops/migrations/README
exclude src/fidesops/migrations/script.py.mako

global-exclude *.pyc
File renamed without changes.
26 changes: 0 additions & 26 deletions src/fidesops/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,6 @@ class Config:
env_prefix = "FIDESOPS__EXECUTION__"


class PackageSettings(FidesSettings):
"""Configuration settings for the fidesops package itself."""

PATH: Optional[str] = None

@validator("PATH", pre=True)
def ensure_valid_package_path(cls, v: Optional[str]) -> str:
"""
Ensure a valid path to the fidesops src/ directory is provided.

This is required to enable fidesops-plus to start successfully.
"""

if isinstance(v, str) and os.path.isdir(v):
return (
v if os.path.basename(v) == "fidesops" else os.path.join(v, "fidesops/")
)

current_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.normpath(os.path.join(current_dir, "../../"))

class Config:
env_prefix = "FIDESOPS__PACKAGE__"


class RedisSettings(FidesSettings):
"""Configuration settings for Redis."""

Expand Down Expand Up @@ -253,7 +228,6 @@ class FidesopsConfig(FidesSettings):
"""Configuration variables for the FastAPI project"""

database: DatabaseSettings
package = PackageSettings()
redis: RedisSettings
security: SecuritySettings
execution: ExecutionSettings
Expand Down
21 changes: 8 additions & 13 deletions src/fidesops/db/database.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
"""
Contains all of the logic for spinning up/tearing down the database.
"""
import os
from os import path

from alembic import command
from alembic.config import Config
from alembic.migration import MigrationContext
from pydantic import PostgresDsn

from fidesops.core.config import config
from fidesops.db.session import get_db_engine

from .base import Base


def get_alembic_config(
database_url: str,
package_source_dir: str = config.package.PATH,
) -> Config:
def get_alembic_config(database_url: str) -> Config:
"""
Do lots of magic to make alembic work programmatically.
"""

migrations_dir = os.path.join(package_source_dir, "migrations/")
alembic_config = Config(os.path.join(package_source_dir, "alembic.ini"))
current_dir = path.dirname(path.abspath(__file__))
migrations_dir = path.abspath(path.join(current_dir, "../migrations"))

alembic_config = Config(path.abspath(path.join(current_dir, "../alembic.ini")))
alembic_config.set_main_option("script_location", migrations_dir.replace("%", "%%"))
alembic_config.set_main_option("sqlalchemy.url", database_url)
return alembic_config
Expand All @@ -35,14 +33,11 @@ def upgrade_db(alembic_config: Config, revision: str = "head") -> None:
command.upgrade(alembic_config, revision)


def init_db(
database_url: PostgresDsn,
package_source_dir: str = config.package.PATH,
) -> None:
def init_db(database_url: PostgresDsn) -> None:
"""
Runs the migrations and creates all of the database objects.
"""
alembic_config = get_alembic_config(database_url, package_source_dir)
alembic_config = get_alembic_config(database_url)
upgrade_db(alembic_config)


Expand Down
2 changes: 1 addition & 1 deletion src/fidesops/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def start_webserver() -> None:

if config.database.ENABLED:
logger.info("Running any pending DB migrations...")
init_db(config.database.SQLALCHEMY_DATABASE_URI, config.package.PATH)
init_db(config.database.SQLALCHEMY_DATABASE_URI)

scheduler.start()

Expand Down
File renamed without changes.
File renamed without changes.