Skip to content

Commit

Permalink
Doc: Add page containing list of Database Migrations (apache#16181)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaxil authored Jun 3, 2021
1 parent 04454d5 commit cefa46a
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,13 @@ repos:
pass_filenames: false
require_serial: true
additional_dependencies: ['pyyaml']
- id: verify-db-migrations-documented
name: Verify that DB Migrations have been documented
language: python
entry: ./scripts/ci/pre_commit/pre_commit_migration_documented.py
files: ^airflow/migrations/versions/.*\.(py)$
pass_filenames: false
require_serial: true
- id: sort-in-the-wild
name: Sort INTHEWILD.md alphabetically
entry: ./scripts/ci/pre_commit/pre_commit_sort_in_the_wild.sh
Expand Down
2 changes: 1 addition & 1 deletion BREEZE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2246,7 +2246,7 @@ This is the current syntax for `./breeze <./breeze>`_:
restrict-start_date rst-backticks setup-order setup-extra-packages shellcheck
sort-in-the-wild sort-spelling-wordlist stylelint trailing-whitespace ui-lint
update-breeze-file update-extras update-local-yml-file update-setup-cfg-file
version-sync www-lint yamllint
verify-db-migrations-documented version-sync www-lint yamllint
You can pass extra arguments including options to the pre-commit framework as
<EXTRA_ARGS> passed after --. For example:
Expand Down
2 changes: 2 additions & 0 deletions STATIC_CODE_CHECKS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ require Breeze Docker images to be installed locally:
----------------------------------- ---------------------------------------------------------------- ------------
``update-extras`` Updates extras in the documentation
----------------------------------- ---------------------------------------------------------------- ------------
``verify-db-migrations-documented`` Verify DB Migrations have been documented
----------------------------------- ---------------------------------------------------------------- ------------
``www-lint`` Static checks of js in airflow/www/static/js/ folder
----------------------------------- ---------------------------------------------------------------- ------------
``yamllint`` Checks YAML files with yamllint
Expand Down
1 change: 1 addition & 0 deletions breeze-complete
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ update-breeze-file
update-extras
update-local-yml-file
update-setup-cfg-file
verify-db-migrations-documented
version-sync
www-lint
yamllint
Expand Down
1 change: 1 addition & 0 deletions docs/apache-airflow/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ unit of work and continuity.
deprecated-rest-api-ref
Configurations <configurations-ref>
Extra packages <extra-packages-ref>
Database Migrations <migrations-ref>
206 changes: 206 additions & 0 deletions docs/apache-airflow/migrations-ref.rst

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions scripts/ci/pre_commit/pre_commit_migration_documented.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python3
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""
Module to verify that migrations added have been documented in
docs/apache-airflow/migrations-ref.rst
"""
import glob
import os
import re
import sys


def check_migration_is_documented(migration_file, doc_path):

with open(migration_file) as m_file:
file_contents = m_file.read()
match = re.search(r"revision\s*=\s*['\"](\w*)['\"]", file_contents)
if match:
revision_id = match.group(1)
with open(doc_path) as doc_file:
doc_file_contents = doc_file.read()
if revision_id not in doc_file_contents:
return False, revision_id
return True, None


if __name__ == '__main__':
project_root = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir)

airflow_migrations_dir = os.path.join(project_root, "airflow/migrations/versions")

doc_path = os.path.abspath(os.path.join(project_root, "docs/apache-airflow/migrations-ref.rst"))
assert os.path.isfile(doc_path)

airflow_migrations_dir = os.path.abspath(airflow_migrations_dir)
migration_files = [f for f in glob.glob(f"{airflow_migrations_dir}/*.py")]

undocumented_migrations = []

for migration_file in migration_files:
is_documented, rev = check_migration_is_documented(migration_file=migration_file, doc_path=doc_path)
if not is_documented:
undocumented_migrations.append((migration_file, rev))

if undocumented_migrations:
print()
print(f"DB Migrations in following files have not been documented in '{doc_path}'")
print()
for undocumented_migration, rev in undocumented_migrations:
print(f"\t- {undocumented_migration} (Revision ID: '{rev}')")
sys.exit(1)

0 comments on commit cefa46a

Please sign in to comment.