I have a view created that I'm binding to a domain-class.
How do I get database-migration to ignore this view so it doesn't attempt to drop it every time dbm-gorm-diff is ran?
You can use the ignoredObjects config setting (docs here), e.g.
grails.plugin.databasemigration.ignoredObjects = ['dont_drop_me_bro']
Related
I read somewhere that if I start a table with |script| on a line by itself, without specifying a fixture name, FitNesse / Slim will reuse the fixture from the previous script table:
|script|my script table fixture|
|check|do something|ok|
Then something else happens, but later I want to keep using that fixture:
|script|
|check|do something else|ok|
But now I can't find where this is documented. It's not mentioned on the documentation page for script tables. Where is this feature actually described?
It is on the page you linked, although not too clearly:
If there is no actor specified then the previous script table's actor on this test page will be used.
I am working on a multi-tenant architecture based plugin, where I am adding a tenantId variable on few domain classes. Now this variable gets assigned its value automatically at object creation time via some code in Domain class itself and the User need not assign it manually.
Now the problem is that I need to provide this functionality to other developers and who actually generate the GSP views using grails generate-views com.something.someClass.
By doing this the generated view also has field for selection of tenant. So is there any domain class constraint or any setting that I can apply to prevent this variable from being automatically included in the view?
P.S. - Any such setting will be anytime better than manual removal of field from view each time.
Thanks.
Try follow steps:
1- run this command to copies the the templates used by Grails during code generation
grails install-templates
2- then open _form file (found in src/templates/scaffolding folder)
3- add tenantId in excludedProps variable like grails did with version field
excludedProps = Event.allEvents.toList() << 'version' << ... << 'tenantId'
Note- I haven't tried this.
I want to know if there is a way to drop and create database manually. I want to execute this code in the init method of BootStrap.groovy.
I am aware that we can set the dataSource to create-drop mode to achieve this when the application starts but I still want to have some sort of manual way to do this.
EDIT:
What I want to do is to clear my database and reload it with some dummy data while my app is running.
You can have a dbManager script which will hold your manually customizing code.
Use below code into your BootStrap.groovy file to call your script.
It also runs based on your environment.
def dbManager =("grails -Dgrails.env="+Environment.currentEnvironment+" run-script scripts/dbManager.groovy").execute()
dbManager.waitForProcessOutput( System.out, System.err )
I'm trying to customize the HTML markup of the excellent FilterPane grails plugin, however I'm having some difficulty. FilterPane provides a bunch of tags for rendering the search/filter form, and I would like to override these in my application.
I had thought that I could simply copy the _tagName.gsps that I wanted to override from
plugins/filterpane-2.0.1.1/grails-app/views/filterpane
into
grails-app/views/filterpane
and modify them, however it looks like Grails never checks whether the application is overriding the views of a plugin, if the render method is called with a plugin name property specified.
org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateRenderer.findAndCacheTemplate contains the following code in a private method:
...
GroovyPageScriptSource scriptSource;
if (pluginName == null) {
scriptSource = groovyPageLocator.findTemplateInBinding(templatePath, pageScope);
} else {
scriptSource = groovyPageLocator.findTemplateInBinding(pluginName, templatePath, pageScope);
}
...
so when a non-null pluginName is specified, we just grab the plugin's view and never check whether the application is overriding it.
I thought a simple way to get around this problem would be to just override GrailsConventionGroovyPageLocator.findTemplateInBinding, or some other similar method in GrailsConventionGroovyPageLocator, however it doesn't appear to be possible to do this from within a Grails application either!
I created a simple class overriding GrailsConventionGroovyPageLocator, replacing the findTemplateInBinding method with one that checks the application's view directory before checking that of the plugin. I then modified resources.groovy, adding a doWithSpring closure to replace the beanClass property of the default groovyPageLocator:
def doWithSpring = {
def pageLocator = delegate.getBeanDefinition("groovyPageLocator")
pageLocator.beanClass = MyConventionGroovyPageLocator
}
However this doesn't seem to be called when my application starts up.
I'm really at a loss here. I'd expected this to be straightforward, but it's turned into a bit of a can of worms. Does anyone have any suggestions? All I want to do is override the views provided by a plugin...
You can modify the plugin source, instead of changing the location of the template.
The location is: user_home\.grails\version\projects\project\plugins\plugin-name
I am not a grails expert, but in order to override plugin views you should recreate them in your main projects views folder. For example, I changed the /auth/login.gsp from Spring Security Plugin by simply creating the same thing in my /project/views/auth/login.gsp. If you make changes into the plugin files itself you could potentially lose them if you uninstall the plugin.
In order to change a view in a template of a plugin, perform the command
grails install-templates
source
This will copy the templates of the plugins to your project which you then can customize. What this does with for example the scaffolding plugin, is copy files to src/templates/scaffolding (note, not grails-app/templates/scaffolding). Therefore, in your case, I would try copying the files to src/views/filterpane
Is that possible to define some kind of mapping in grails so CREATE TABLE is replaced with CREATE MEMORY TABLE for particular grails domains?
If you wanted to do this for all tables, you could create a custom Dialect and override getCreateTableString() but there's no way to know the current table name, so it can be selectively applied.
But you can take the approach I suggested here: grails limited table creation. You would just override generateSchemaCreationScript() and if you find the table(s) you're looking for, you can replace the 'create table' string with 'create memory table'.
The create table statements are generated by Hibernate's hbm2ddl feature. I don't think there is a way to configure the syntax of the create statement other than the table name itself and the columns.
You would have to manually manage the schema creation using a plugin like Autobase or Liquibase (or whatever they have coming in Grails 1.4 to handle DB migrations).