Laravel 5.1:根据app config选择迁移文件夹

时间:2016-12-21 09:08:34

标签: php laravel-5 laravel-migrations

基本上,我想在app/database/migrations文件夹中放置两个不同的文件夹,只从其中一个加载迁移

 - migrations
     - folder 1
     - folder 2

当我运行php artisan migrate时,我希望它查看我的config/app.php并确定需要执行哪些文件。有可能吗?

2 个答案:

答案 0 :(得分:1)

是的,您可以从特定文件夹迁移。只需在运行迁移时添加 --path

喜欢:php artisan migrate --path='database/migrations/folder1'

答案 1 :(得分:0)

不确定我们是否可以使用您的 Laravel 版本 (5.1),从 5.3 Laravel 开始支持 // here's the function that decreases playerEnergy, which is triggered by a button // Game.tsx const [playerEnergy, setPlayerEnergy] = useAtom(playerEnergyAtom); const decreaseEnergy = () => { setPlayerEnergy(playerEnergy <= 0 ? 0 : playerEnergy - 10); }; // then I watch playerEnergy and set the an event state to NO_ENERGY if it is 0 // EnergyLevel.tsx const [, setEventTriggeredOfType] = useAtom(eventTriggeredOfTypeAtom); useEffect(() => { if (playerEnergy <= 0) setEventTriggeredOfType(EventType.NO_ENERGY); }, [playerEnergy, setEventTriggeredOfType]); // here is the EndGame component that is only rendered when // shouldTriggerEndGame returns true // Game.tsx const [shouldTriggerEndGame] = useAtom(shouldTriggerEndGameAction); if (shouldTriggerEndGame) return <EndGame />; // here is the shouldTriggerEndGame atom that checks the event state // gameActions.ts (this file holds all the atoms) export const shouldTriggerEndGameAction = atom((get) => { // this is what returns stale atom value SOMETIMES const eventTriggeredOfType = get(eventTriggeredOfTypeAtom); return [ eventTriggeredOfType === EventType.NO_ENERGY ].some((triggerState: boolean): boolean => triggerState === true); }); // here is the "Start Over" button handler that resets the EventType above: // EndGame.tsx const goBackToMainMenu = () => { setEventTriggeredOfType(EventType.NONE); // triggers a return to the main screen (always works) setActiveScreen(Screen.NONE); }; // these are triggered by UI buttons from the user // gameActions.ts export const startNewGameAction = atom(null, (_get, set) => { set(resetDefaultGameState, null); set(isLoadingGameOfTypeAtom, LoadType.NEW); }); export const loadLastGameAction = atom(null, (_get, set) => { set(resetDefaultGameState, null); set(isLoadingGameOfTypeAtom, LoadType.SAVED); }); // isLoadingGameOfType is being watched from within <Game /> // Game.tsx const loadSavedGameRef = useRef(loadSavedGame); const createNewGameRef = useRef(createNewGame); useEffect(() => { if (isLoadingGameOfType === LoadType.SAVED) loadSavedGameRef.current(); if (isLoadingGameOfType === LoadType.NEW) createNewGameRef.current(); }, [isLoadingGameOfType]); // these are triggered by <Game />'s useEffects when the appropriate // eventTriggeredOfType values are true // gameActions.ts export const loadSavedGameAction = atom(null, async (get, set) => { const playerData = get(playerDataAtom); set(playerEnergyAtom, playerData.lastGameState.playerEnergy); }); export const createNewGameAction = atom(null, (_get, set) => { set(playerEnergyAtom, 100); }); 方法。

通过向 loadMigrationsFrom 类的 boot 方法添加以下行,我注册了自定义迁移路径以放置所有触发器定义。

App\Providers\AppServiceProvider