I have the following CREATE TABLE ${schema_name}.TABLE and CREATE TABLE #[schema_name].TABLE.
I have some migrations to do with Flyway and the ones with # do not work.
What is the difference between these two? (given that the ones with # are from working code)
There was a special configuration made in flyway properties file:
flyway.placeholderPrefix=#[
flyway.placeholderSuffix=]
Related
I have a question regarding Flyway and managing multiple schemas. I have multiple schemas (schema1, schema2, schema3) with different deployment schedules and different folder locations (sql/schema1, sql/schema2, sql/schema3) with different code.
I want to Flyway to create the schemas before the code deployment but how do I set this up in a single config file? I read the Flyway doc (https://flywaydb.org/documentation/faq#multiple-schemas) but is the example using a single config file? or do i need to create multiple config files (one per schema)?
Can i achieve the same setting comma delimited schema list? will "Schema1" only look in the "sql/Schema1" location? I really dont want Schema1 pulling code from a different folder i.e. sql/Schema2, etc.
Thanks in advance!
When using Flyway with multiple schemas, you need to explicitly say in the sql statements which schema the sql is going to change. You can do this by putting an ALTER SESSION SET CURRENT_SCHEMA=schema1 at the top of each migration file, or prefixing all your statements like CREATE TABLE schema1.bananas.
If this is not practical, it would be best to create a number of config files, each with a single schema specified, and a single location specified. e.g.
flyway.schemas=schema1
flyway.locations=filesystem:sql/schema1
Then you can run Flyway with each config file individually to migrate that particular schema.
I've seen how to rename the DATABASECHANGELOG tables but what I'm looking to do is to have them created in one database for each server and then deploy to the other databases on that server. We are using Liquibase on MSSQL and Sybase databases and executing via command line.
Thoughts?
I've had the same thought before as well. That's just not how it's done at my current shop :)
You're looking for these options:
--liquibaseCatalogName=<name> The name of the catalog with the
liquibase tables
--liquibaseSchemaName=<name> The name of the schema with the
liquibase tables
Doc here: http://www.liquibase.org/documentation/command_line.html.
However, --liquibaseCatalogName is not documented, but it does appear as an option when checking the command line options via liquibase --help. In your case, I believe "Catalog" equates to a Database in MSSQL and Sybase.
Oracle 11gR2
Linux RHEL 6.3
Subversion 1.7
Trying to find a build tool like 'make', 'ant', 'maven' for Oracle PL/SQL or SQL that will allow me to build my Oracle PL/SQL and SQL application. Seems I can't find tool that will, for example, maintain the precedence needed to run my SQL (e.g. DDL) in the correct order. I can compare differences between two schemas and generate DDL that will sync the two schemas. But the order that this DDL is generated in does not take into account precedence -- e.g. parent table build should occur before child table but instead the DDL output is in alphabetical order.
Any ideas?
I use make and a make file like this. But I have the db password in the file! Also all ddl creation files are separate in the same folder. You need at least the oracle instant client with sqlplus installed.
# When on Windows and starting GNU make from Git bash, we need to set this:
ifdef COMSPEC
SHELL=C:/Windows/System32/cmd.exe
endif
export ORASYSDBA="sys/oracle#192.168.0.112:1521/orcl as sysdba"
uninstall:
sqlplus ${ORASYSDBA} #uninstall.sql
install: tablespaces users directories sequences package_reapi_headers tables types views sysgrants package_headers package_bodies
sqlplus ${ORASYSDBA} #create_directories.sql
tablespaces:
sqlplus ${ORASYSDBA} #create_tablespaces.sql
users:
sqlplus ${ORASYSDBA} #create_users.sql
You then simply call it by
make install
or
make users
I have a specific SQL file that may be "connected" to another, more generic SQL init file.
Is it possible to somehow include reference from one SQL file to another SQL file?
I am using Oracle and the DB is populated using Spring DataSourceInitializer class.
If you are using SQL*Plus to run your script, you can use the # (or ##) sign to include another SQL script.
See the manual for details:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12002.htm#i2696724
http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch12003.htm#i2696759
I'm trying to reset a database in Django, using:
python manage.py reset app
but get the following error:
Error: Error: app couldn't be reset. Possible reasons:
* The database isn't running or isn't configured correctly.
* At least one of the database tables doesn't exist.
* The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlreset app'. That's the SQL this command wasn't able to run.
The full error: cannot drop table app_record because other objects depend on it
HINT: Use DROP ... CASCADE to drop the dependent objects too.
This is what my models.py file looks like:
class Record(models.Model):
name = models.CharField(max_length=50, db_index=True)
year = models.IntegerField(blank=True, null=True)
def __unicode__(self):
return self.name
class Class(models.Model):
record = models.ForeignKey(Record)
def __unicode__(self):
return self.id
I get that I need to use the DROP... CASCADE command in the SQL that deletes and recreates the database (the output of django-admin.py).
But how can I edit that SQL directly from models.py?
UPDATE
OK, I figured out how to delete tables manually (the database is postgres), have noted it here for anyone with the same problem:
python manage.py dbshell
# drop table app_record cascade;
# \q
python manage.py reset app
Would still like to know if anyone has a better way to do it, though :)
The easy way to fully reset a Django database is using django-extensions.
It has a reset_db command that supports all Django's default database backends.
python manage.py reset_db
If you're using Django 1.2+ you should explicitly define the database you want to reset. If your project only uses one database, you should probably set --router=default
I use a little unix pipeline that adds CASCADE to all the DROP statements.
python manage.py sqlreset myapp | sed 's/DROP TABLE \(.*\);/DROP TABLE \1 CASCADE;/g' | \
psql --username myusername mydbname
The problem of DROP TABLE CASCADE is that it just remove a foreign keys on related tables - after syncdb this relation is not recreated.
I found no way to recreate the particular model's tables, so I'm reseting whole application by recreating schema:
DROP SCHEMA public CASCADE;
CREATE SCHEMA "public" AUTHORIZATION "owner of database";
That should work only with database that supports schema, e.g. postgresql
Using the details in other answers, I made a bash function that I dropped into ~/.bash_profile (on Mac OS X).
django_reset () { python mainsite/manage.py sqlreset "$*" | sed 's/DROP TABLE \(.*\);/DROP TABLE \1 CASCADE;/g' | mainsite/manage.py dbshell ; }
Then just run this command in the terminal from your root code directory (so the path to mainsite/manage.py makes sense).
django_reset myappA myappB
And it'll execute!
I found another way. I'm using sqlite3 that comes by default in Django.
To reset table to default.
python manage.py flush --database=default
after this you will need to use the syncdb command again.