diff --git a/.github/workflows/test-without-model.yml b/.github/workflows/test-without-model.yml index 4b8f0ab..65bebad 100644 --- a/.github/workflows/test-without-model.yml +++ b/.github/workflows/test-without-model.yml @@ -1,7 +1,7 @@ name: Run Pytest without Model on: - push: - branches: [develop] + pull_request: + types: [opened, reopened, synchronize, ready_for_review] env: WORKING_DIRECTORY: application @@ -36,17 +36,22 @@ jobs: --health-timeout 5s --health-retries 5 steps: + # https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches - name: Chekcout code uses: actions/checkout@v4 + with: + fetch-depth: 0 + # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idif - name: Check for model changes + # https://www.ibm.com/docs/ja/aix/7.1?topic=g-grep-command#grep__row-d3e144113 id: check_changes run: | - BASE_BRANCH=${{ github.base_ref }} - git fetch origin $BASE_BRANCH MODEL_CHANGED=false - if git diff --name-only origin/$BASE_BRANCH ${{ github.sha }} | grep -q "^${{ env.WORKING_DIRECTORY }}/models/"; then + if git diff --name-only origin/${{ github.base_ref }} | grep -c ${{ env.WORKING_DIRECTORY }}/application/models/ > 0; then + echo $MODEL_CHANGED MODEL_CHANGED=true fi + echo $MODEL_CHANGED echo "MODEL_CHANGED=$MODEL_CHANGED" >> $GITHUB_ENV - name: Grant privileges to user run: mysql --protocol=tcp -h 127.0.0.1 -P 3306 -u root -p$MYSQL_ROOT_PASSWORD -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%'; FLUSH PRIVILEGES;" @@ -55,15 +60,15 @@ jobs: with: working-directory: ${{ env.WORKING_DIRECTORY }} - name: Run migration - run: | - poetry run python manage.py makemigrations - poetry run python manage.py migrate + run: poetry run python manage.py migrate - name: Run Pytest Without Model - if: env.MODEL_CHANGED == 'true' + # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idif + if: env.MODEL_CHANGED == 'false' run: | set -o pipefail poetry run pytest ${{ env.WORKING_DIRECTORY }}/tests/serializers ${{ env.WORKING_DIRECTORY }}/tests/views --junitxml=pytest.xml -x -n auto --cov --no-cov-on-fail --suppress-no-test-exit-code | tee pytest-coverage.txt - name: Run Pytest + if: env.MODEL_CHANGED == 'true' run: | set -o pipefail poetry run pytest --junitxml=pytest.xml -x -n auto --cov --no-cov-on-fail --suppress-no-test-exit-code | tee pytest-coverage.txt diff --git a/.gitignore b/.gitignore index ae15ce2..07e1563 100644 --- a/.gitignore +++ b/.gitignore @@ -160,7 +160,6 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ # ignore migration files -migrations/ # ignore static files static/ settings.json diff --git a/0 b/0 new file mode 100644 index 0000000..573541a --- /dev/null +++ b/0 @@ -0,0 +1 @@ +0 diff --git a/application/application/migrations/0001_initial.py b/application/application/migrations/0001_initial.py new file mode 100644 index 0000000..625c277 --- /dev/null +++ b/application/application/migrations/0001_initial.py @@ -0,0 +1,228 @@ +# Generated by Django 4.2.1 on 2023-05-14 10:29 + +import uuid + +import django.contrib.auth.models +import django.contrib.auth.validators +import django.core.validators +import django.db.models.deletion +from django.db import migrations, models + +import application.utils.customer_storage + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ("auth", "0012_alter_user_first_name_max_length"), + ] + + operations = [ + migrations.CreateModel( + name="Address", + fields=[ + ( + "id", + models.UUIDField( + default=uuid.uuid4, + editable=False, + primary_key=True, + serialize=False, + ), + ), + ("prefecture", models.CharField(max_length=255)), + ("municipalities", models.CharField(max_length=255)), + ("house_no", models.CharField(max_length=255)), + ("other", models.CharField(blank=True, max_length=255)), + ( + "post_no", + models.CharField( + max_length=7, + null=True, + validators=[ + django.core.validators.RegexValidator( + "^[0-9]{7}$", "7桁の数字を入力してください。" + ) + ], + ), + ), + ], + options={ + "db_table": "Address", + }, + ), + migrations.CreateModel( + name="Customer", + fields=[ + ( + "id", + models.UUIDField( + default=uuid.uuid4, + editable=False, + primary_key=True, + serialize=False, + ), + ), + ("kana", models.CharField(max_length=255)), + ("name", models.CharField(max_length=255)), + ("birthday", models.DateField()), + ( + "phone_no", + models.CharField( + blank=True, + max_length=11, + validators=[ + django.core.validators.RegexValidator( + "^[0-9]{11}$", "11桁の数字を入力してください。" + ) + ], + ), + ), + ( + "address", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="address", + to="application.address", + ), + ), + ], + options={ + "db_table": "Customer", + }, + ), + migrations.CreateModel( + name="CustomerPhoto", + fields=[ + ( + "id", + models.UUIDField( + default=uuid.uuid4, + editable=False, + primary_key=True, + serialize=False, + ), + ), + ( + "photo", + models.ImageField( + storage=application.utils.customer_storage.CustomerStorage(), + upload_to="customer_photo", + ), + ), + ( + "customer", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="application.customer", + ), + ), + ], + options={ + "db_table": "CustomerPhoto", + }, + ), + migrations.CreateModel( + name="User", + fields=[ + ( + "password", + models.CharField(max_length=128, verbose_name="password"), + ), + ( + "last_login", + models.DateTimeField( + blank=True, null=True, verbose_name="last login" + ), + ), + ( + "is_superuser", + models.BooleanField( + default=False, + help_text="Designates that this user has all permissions without explicitly assigning them.", + verbose_name="superuser status", + ), + ), + ( + "is_staff", + models.BooleanField( + default=False, + help_text="Designates whether the user can log into this admin site.", + verbose_name="staff status", + ), + ), + ( + "is_active", + models.BooleanField( + default=True, + help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.", + verbose_name="active", + ), + ), + ( + "id", + models.UUIDField( + default=uuid.uuid4, + editable=False, + primary_key=True, + serialize=False, + ), + ), + ( + "employee_number", + models.CharField( + max_length=8, + unique=True, + validators=[ + django.core.validators.RegexValidator("^[0-9]{8}$") + ], + verbose_name="社員番号", + ), + ), + ( + "username", + models.CharField( + max_length=150, + unique=True, + validators=[ + django.contrib.auth.validators.UnicodeUsernameValidator() + ], + ), + ), + ("email", models.EmailField(max_length=254, unique=True)), + ( + "role", + models.PositiveIntegerField( + choices=[ + (0, "Management"), + (1, "General"), + (2, "Part Time"), + ], + default=2, + ), + ), + ("created_at", models.DateTimeField(auto_now_add=True)), + ("updated_at", models.DateTimeField(auto_now=True)), + ( + "user_permissions", + models.ManyToManyField( + blank=True, + help_text="Specific permissions for this user.", + related_name="user_set", + related_query_name="user", + to="auth.permission", + verbose_name="user permissions", + ), + ), + ], + options={ + "db_table": "User", + "ordering": ["employee_number"], + }, + managers=[ + ("objects", django.contrib.auth.models.UserManager()), + ], + ), + ] diff --git a/application/application/migrations/0002_alter_address_table_comment_and_more.py b/application/application/migrations/0002_alter_address_table_comment_and_more.py new file mode 100644 index 0000000..1df6303 --- /dev/null +++ b/application/application/migrations/0002_alter_address_table_comment_and_more.py @@ -0,0 +1,146 @@ +# Generated by Django 4.2.1 on 2023-06-01 11:36 + +import uuid + +import django.contrib.auth.validators +import django.core.validators +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("application", "0001_initial"), + ] + + operations = [ + migrations.AlterModelTableComment( + name="address", + table_comment="住所", + ), + migrations.AlterModelTableComment( + name="customer", + table_comment="システムユーザ", + ), + migrations.AlterModelTableComment( + name="customerphoto", + table_comment="お客様の画像", + ), + migrations.AlterModelTableComment( + name="user", + table_comment="システムユーザ", + ), + migrations.AlterField( + model_name="customer", + name="address", + field=models.ForeignKey( + db_comment="住所ID", + on_delete=django.db.models.deletion.CASCADE, + related_name="address", + to="application.address", + ), + ), + migrations.AlterField( + model_name="customer", + name="birthday", + field=models.DateField(db_comment="誕生日"), + ), + migrations.AlterField( + model_name="customer", + name="id", + field=models.UUIDField( + db_comment="お客様ID", + default=uuid.uuid4, + editable=False, + primary_key=True, + serialize=False, + ), + ), + migrations.AlterField( + model_name="customer", + name="kana", + field=models.CharField(db_comment="カナ氏名", max_length=255), + ), + migrations.AlterField( + model_name="customer", + name="name", + field=models.CharField(db_comment="氏名", max_length=255), + ), + migrations.AlterField( + model_name="customer", + name="phone_no", + field=models.CharField( + blank=True, + db_comment="電話番号", + max_length=11, + validators=[ + django.core.validators.RegexValidator( + "^[0-9]{11}$", "11桁の数字を入力してください。" + ) + ], + ), + ), + migrations.AlterField( + model_name="user", + name="created_at", + field=models.DateTimeField(auto_now_add=True, db_comment="作成日"), + ), + migrations.AlterField( + model_name="user", + name="email", + field=models.EmailField( + db_comment="メールアドレス", max_length=254, unique=True + ), + ), + migrations.AlterField( + model_name="user", + name="employee_number", + field=models.CharField( + db_comment="社員番号", + max_length=8, + unique=True, + validators=[ + django.core.validators.RegexValidator("^[0-9]{8}$") + ], + verbose_name="社員番号", + ), + ), + migrations.AlterField( + model_name="user", + name="id", + field=models.UUIDField( + db_comment="システムユーザID", + default=uuid.uuid4, + editable=False, + primary_key=True, + serialize=False, + ), + ), + migrations.AlterField( + model_name="user", + name="role", + field=models.PositiveIntegerField( + choices=[(0, "Management"), (1, "General"), (2, "Part Time")], + db_comment="システムユーザのロール", + default=2, + ), + ), + migrations.AlterField( + model_name="user", + name="updated_at", + field=models.DateTimeField(auto_now=True, db_comment="更新日"), + ), + migrations.AlterField( + model_name="user", + name="username", + field=models.CharField( + db_comment="ユーザ名", + max_length=150, + unique=True, + validators=[ + django.contrib.auth.validators.UnicodeUsernameValidator() + ], + ), + ), + ] diff --git a/application/application/migrations/0003_alter_address_house_no_alter_address_id_and_more.py b/application/application/migrations/0003_alter_address_house_no_alter_address_id_and_more.py new file mode 100644 index 0000000..17d7c2c --- /dev/null +++ b/application/application/migrations/0003_alter_address_house_no_alter_address_id_and_more.py @@ -0,0 +1,95 @@ +# Generated by Django 4.2.1 on 2023-06-01 11:38 + +import uuid + +import django.core.validators +import django.db.models.deletion +from django.db import migrations, models + +import application.utils.customer_storage + + +class Migration(migrations.Migration): + + dependencies = [ + ("application", "0002_alter_address_table_comment_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="address", + name="house_no", + field=models.CharField(db_comment="丁・番地", max_length=255), + ), + migrations.AlterField( + model_name="address", + name="id", + field=models.UUIDField( + db_comment="住所ID", + default=uuid.uuid4, + editable=False, + primary_key=True, + serialize=False, + ), + ), + migrations.AlterField( + model_name="address", + name="municipalities", + field=models.CharField(db_comment="市区町村", max_length=255), + ), + migrations.AlterField( + model_name="address", + name="other", + field=models.CharField( + blank=True, db_comment="その他(マンション名など)", max_length=255 + ), + ), + migrations.AlterField( + model_name="address", + name="post_no", + field=models.CharField( + db_comment="郵便番号", + max_length=7, + null=True, + validators=[ + django.core.validators.RegexValidator( + "^[0-9]{7}$", "7桁の数字を入力してください。" + ) + ], + ), + ), + migrations.AlterField( + model_name="address", + name="prefecture", + field=models.CharField(db_comment="都道府県", max_length=255), + ), + migrations.AlterField( + model_name="customerphoto", + name="customer", + field=models.ForeignKey( + db_comment="お客様ID", + on_delete=django.db.models.deletion.CASCADE, + to="application.customer", + ), + ), + migrations.AlterField( + model_name="customerphoto", + name="id", + field=models.UUIDField( + db_comment="お客様の写真ID", + default=uuid.uuid4, + editable=False, + primary_key=True, + serialize=False, + ), + ), + migrations.AlterField( + model_name="customerphoto", + name="photo", + field=models.ImageField( + db_comment="写真", + storage=application.utils.customer_storage.CustomerStorage(), + upload_to="customer_photo", + ), + ), + ] diff --git a/application/application/migrations/0004_alter_customer_table_comment.py b/application/application/migrations/0004_alter_customer_table_comment.py new file mode 100644 index 0000000..2f06502 --- /dev/null +++ b/application/application/migrations/0004_alter_customer_table_comment.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.1 on 2023-06-01 11:46 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ( + "application", + "0003_alter_address_house_no_alter_address_id_and_more", + ), + ] + + operations = [ + migrations.AlterModelTableComment( + name="customer", + table_comment="お客様", + ), + ] diff --git a/application/application/models/user.py b/application/application/models/user.py index 9dc36fa..c0a9aaa 100644 --- a/application/application/models/user.py +++ b/application/application/models/user.py @@ -7,7 +7,7 @@ class User(AbstractUser): - """システムユーザ""" + """システムユーザのModel""" username_validator = UnicodeUsernameValidator()