Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic generation for versioned data models #7

Closed
nvie opened this issue Dec 4, 2009 · 5 comments
Closed

Automatic generation for versioned data models #7

nvie opened this issue Dec 4, 2009 · 5 comments

Comments

@nvie
Copy link

nvie commented Dec 4, 2009

When you have added a version to your Core Data model (Design > Data Model > Add Model Version), automatic entity generation using the 'xmod' comment text stops working.

It's not exactly clear to me whether this should work, is still unimplemented, or whether the 'xmod' comment tag should be placed elsewhere (for example on the .xcdatamodeld directory?).

Any experiences with versioned models and auto-generating classes?

@amrox
Copy link

amrox commented Dec 4, 2009

I'm just using mogenerator directly, and not the automatic generation with xmod.

I wrote a script around mogenerator to grab the current model version. Here are the pertinent lines:

DATAMODEL_WRAPPER="path/to/your/model.xcdatamodeld"
DATAMODEL_CURRENT=`/usr/libexec/PlistBuddy -c "print _XCCurrentVersionName" "$DATAMODEL_WRAPPER"/.xccurrentversion`
DATAMODEL_PATH="$DATAMODEL_WRAPPER/$DATAMODEL_CURRENT"

@rentzsch
Copy link
Owner

Yeah, I haven't implemented direct support for versioned models yet. Patches welcome :-)

@adib
Copy link

adib commented Jan 16, 2010

Here's a preliminary script that can be used as a build phase from amrox's script:

#!/bin/bash
# mogeneratorv MoGenenerator for versioned model
# http://github.com/rentzsch/mogenerator/issues/unreads#issue/7
#
# Revision History
# 16-Jan-10     Sasmito Adibowo     initial creation
#

DATAMODEL_WRAPPER="$1"
if [ ! -f "$DATAMODEL_WRAPPER/.xccurrentversion" ];
then
    echo  file "$DATAMODEL_WRAPPER/.xccurrentversion" does not exists - exiting.
    exit 3
fi
DATAMODEL_CURRENT=`/usr/libexec/PlistBuddy -c "print _XCCurrentVersionName" "$DATAMODEL_WRAPPER"/.xccurrentversion`
DATAMODEL_PATH="$DATAMODEL_WRAPPER/$DATAMODEL_CURRENT"
DATAMODEL_FILE=`basename "$DATAMODEL_PATH"`
DATAMODEL_DIR=`dirname "$DATAMODEL_WRAPPER"`
DATAMODEL_NAME=`expr "$DATAMODEL_FILE" : "\(.*\)\.xcdatamodel"`

echo Data model: "$DATAMODEL_PATH"
echo Model directory: "$DATAMODEL_DIR" 
echo Output Directory: "$DATAMODEL_DIR/$DATAMODEL_NAME"

if [ ! -d "$DATAMODEL_DIR/$DATAMODEL_NAME" ]
then
    mkdir "$DATAMODEL_DIR/$DATAMODEL_NAME"
fi


mogenerator -m "$DATAMODEL_PATH" -O "$DATAMODEL_DIR/$DATAMODEL_NAME"

@adib
Copy link

adib commented Nov 20, 2010

Looks like version 1.21 broke the ability to generate versioned data model. Here is an update to the workaround script. The script now correctly identify the versioned data model name as the output directory

#!/bin/bash
# mogeneratorv MoGenenerator for versioned model
# https://github.com/rentzsch/mogenerator/issues/7
# Revision History
# 16-Jan-10 Sasmito Adibowo initial creation
# 20-Nov-10 Sasmito Adibowo Now uses the versioned data model name as the base name for the output directory

DATAMODEL_WRAPPER="$1"
if [ ! -f "$DATAMODEL_WRAPPER/.xccurrentversion" ];
then
    echo  file "$DATAMODEL_WRAPPER/.xccurrentversion" does not exists - exiting.
    exit 3
fi
DATAMODEL_CURRENT=`/usr/libexec/PlistBuddy -c "print _XCCurrentVersionName" "$DATAMODEL_WRAPPER"/.xccurrentversion`
DATAMODEL_PATH="$DATAMODEL_WRAPPER/$DATAMODEL_CURRENT"
DATAMODEL_FILE=`basename "$DATAMODEL_PATH"`
DATAMODEL_DIR=`dirname "$DATAMODEL_WRAPPER"`

WRAPPER_NAME=`basename ${DATAMODEL_WRAPPER}`
DATAMODEL_NAME="${WRAPPER_NAME%.*}"

echo Data model: "$DATAMODEL_PATH"
echo Model directory: "$DATAMODEL_DIR" 
echo Output Directory: "$DATAMODEL_DIR/$DATAMODEL_NAME"

if [ ! -d "$DATAMODEL_DIR/$DATAMODEL_NAME" ]
then
    mkdir "$DATAMODEL_DIR/$DATAMODEL_NAME"
fi

mogenerator -m "$DATAMODEL_PATH" -O "$DATAMODEL_DIR/$DATAMODEL_NAME"

@rentzsch
Copy link
Owner

Direct support added: #46

seanm pushed a commit to seanm/mogenerator that referenced this issue Jan 6, 2012
---

This pull request allows to put `xmod` tag on a versionned model *(.xcdatamodel**d**)*
Script then will automatically detect current version and call `mogenerator` on it.

This modification is non intrusive and not breaking existing behavior.
This is a popular request related to several issues : rentzsch#7, rentzsch#14, rentzsch#37

Thanks to nvie who this is largely inspired from : nvie/mogenerator@575584320a03f8738f9e1c42f6e05f865f8aeb5a
ddrccw pushed a commit to ddrccw/mogenerator that referenced this issue Jan 20, 2014
---

This pull request allows to put `xmod` tag on a versionned model *(.xcdatamodel**d**)*
Script then will automatically detect current version and call `mogenerator` on it.

This modification is non intrusive and not breaking existing behavior.
This is a popular request related to several issues : rentzsch#7, rentzsch#14, rentzsch#37

Thanks to nvie who this is largely inspired from : nvie/mogenerator@575584320a03f8738f9e1c42f6e05f865f8aeb5a
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants