如何在Makefile中拥有动态目标?

时间:2018-03-23 13:48:52

标签: makefile

请看下面的Makefile。

ERROR 1215: Cannot add foreign key constraint
SQL Statement:
CREATE TABLE IF NOT EXISTS `documentreferences` (
      `Id` int(5) NOT NULL AUTO_INCREMENT,
      `Status` varchar(50),
      `DocStatus` varchar(50),
      `Type` JSON, -- single CodeableConcept DataType
      `Class` JSON, -- single CodeableConcept DataType
      `Created` datetime,
      `Indexed` datetime, 
      `Description` varchar(50),
      `SecurityLabel` JSON, -- array of CodeableConcept DataTypes
      `ContextEvent` JSON, -- array of CodeableConcept DataTypes
      `ContextPeriodStart` datetime,
      `ContextPeriodEnd` datetime,
      `ContextFacilityType` JSON, -- single CodeableConcept DataType
      `ContextPracticeSetting` JSON, -- single CodeableConcept DataType
      PRIMARY KEY (`id`),
       `SubjectId` int(5),
        INDEX subject_ind (SubjectId),
        FOREIGN KEY (SubjectId)
        REFERENCES patients(Id)
        ON DELETE CASCADE,
        -- ** FK below causes issue **
      `PractitionerId` int(5),
        INDEX practitioner_ind (PractitionerId),
        FOREIGN KEY (PractitionerId)
        REFERENCES practitioners(Id)
        ON DELETE CASCADE
    ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1

有更有效的方法吗?

例如:

compose:
    docker-compose up myapp

compose-shell:
    docker-compose run myapp /bin/bash

compose-shellplus:
    docker-compose run myapp make shell

compose-test:
    docker-compose run myapp make test

compose-migrate:
    docker-compose run myapp make migrate

compose-load:
    docker-compose run myapp make load

compose-export:
    docker-compose run myapp make export

compose-flush:
    docker-compose run myapp make flush

# run tests
test:
    python manage.py test --settings=$(PROJECT_SETTINGS)

# install depedencies (and virtualenv for linux)
install:
ifndef WIN
    -virtualenv -p python3 .venv
endif
    pip install -r requirements.txt

# handle django migrations
migrate:
    python manage.py makemigrations --settings=$(PROJECT_SETTINGS)
    python manage.py migrate --settings=$(PROJECT_SETTINGS)

# handle statics
static:
    python manage.py collectstatic --settings=$(PROJECT_SETTINGS)

shell:
    python manage.py shell_plus --settings=$(PROJECT_SETTINGS)

load:
    python manage.py loaddata db.json --settings=${PROJECT_SETTINGS}

export:
    python manage.py dumpdata --indent 2 --natural-foreign --natural-primary -e sessions -e admin -e contenttypes -e auth.Permission  > db.json --settings=${PROJECT_SETTINGS}

flush:
    python manage.py sqlflush --settings=${PROJECT_SETTINGS}

1 个答案:

答案 0 :(得分:5)

最好在发布SO之前尝试在the documentation中找到答案。这是你可以用GNU make做的最基本的事情之一。

使用pattern rule

compose-%:
        docker-compose run myapp make $*