We have two different envirionments
Dev (develop git branch)
Production (release/1.0 git branch)
release/1.0 release was the first release and a developer has changed the old Flyway files in the release/1.0. So, following are the changes in databases.
$ git diff develop..origin/release/1.0 src/main/resources/db/migration/
diff --git a/src/main/resources/db/migration/V1.7__add_table_css_setting.sql b/src/main/resources/db/migration/V1.7__add_table_css_setting.sql
index 1aff026..b9d916b 100644
--- a/src/main/resources/db/migration/V1.7__add_table_css_setting.sql
+++ b/src/main/resources/db/migration/V1.7__add_table_css_setting.sql
## -1,4 +1,5 ##
CREATE TABLE css_setting(
+ `id` integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
`value` TEXT DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
diff --git a/src/main/resources/db/migration/V1.12__insert_table_css_setting.sql b/src/main/resources/db/migration/V1.12__insert_table_css_setting.sql
index f54c737..e640ab1 100644
--- a/src/main/resources/db/migration/V1.12__insert_table_css_setting.sql
+++ b/src/main/resources/db/migration/V1.12__insert_table_css_setting.sql
## -1 +1 ##
-ALTER TABLE css_setting ADD `id` integer NOT NULL AUTO_INCREMENT PRIMARY KEY;
\ No newline at end of file
+INSERT INTO css_setting(`id`,`value`) VALUES(1,'');
Versions in respective branches have been migrated in respective environments. So,
We cannot merge back the hotfixes in release/1.0 back to develop
In the next production release, we cannot create the release/2.0 from develop
Since this is such small change, I guess one option is to replace develop Flyway files with release/1.0, Flaway clean & migrate the database in the Dev environment so both of them are in the same state.
I'm wondering if Flyway "undo migrations" any help here or if there are any other solutions, just in case this happens in the future.
Related
Create a table statement as follows:
[omm#tpl-centos7 bin]$ ./gsql -ddev -Uomm -p26000 -f test.sql
gsql:test.sql:7: ERROR: column name “tid” conflicts with a system column name
total time: 0 ms
[omm#tpl-centos7 bin]$ cat test.sql
CREATE TABLE if not exists ax_quarantine_rcpt
(
“tid” varchar2(255) NOT NULL,
rcpt varchar2(255) NOT NULL,
org_id varchar2(60) NOT NULL,
PRIMARY KEY (“tid”,rcpt)
);
error:column name “tid” conflicts with a system column name
Looking at the documentation, it says reserved words must never be used as other identifiers, but tid is also not in the keyword
Referring to the Internet with double quotation marks does not work, solve
It may be a version problem. He described that the tid is occupied by the system view field. I can use the latest compiled version. It is recommended to use the latest version.
If you cannot compile it yourself, you can use the container version. https://hub.docker.com/repository/docker/enmotech/opengauss
Consider the code below in a unit test, where I add a new Tag object in a pre-populated SQLite database.
#Test // Line 1
public void add() {
Tag tagToAdd = new Tag("Tall");
Tag addedTag = this.tagDao.add(tagToAdd);
assertNotNull(addedTag);
assertEquals(3L, addedTag.getId()); // Line 6
assertEquals(tagToAdd.getTag(), addedTag.getTag());
List<Tag> tags = this.tagDao.get();
assertEquals(3, tags.size());
}
On line 6, I expect the ID of the Tag to be 3, because the field is an AUTOINCREMENT and the test is initialized with a database already containing 2 Tags. This works fine every time I run the test and the ID is always 3.
Now, I am integrating flyway to the project. Every time I run the test, the AUTOINCREMENT starts from the value of the last run, so the Tag ID increments by 1 every run, and the test fails.
Any idea on how I can get flyway to always reset the database to a brand new state, and reset the AUTOINCREMENT value ? I could write a query to do it manually, but this is not maintainable.
What I have tried so far ?
Integrate #FlywayTest, as this executes flyway task clean
Defined a FlywayMigrationStrategy bean, which contains flyway.clean()
Set spring.flyway.clean-on-validation-error to true in my application.properties (that said, there was no change in my sql, so not sure if this changed anything)
-- Edit
My 1st migration script contains the below.
DROP TABLE IF EXISTS Tag;
CREATE TABLE Tag(
id INTEGER PRIMARY KEY AUTOINCREMENT,
tag VARCHAR(255) NOT NULL UNIQUE,
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modifiedDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
If I understood everything correctly - you have a database and a table in this database which is created once and the same table is used for tests every time - you just delete rows from the table (without removing it) when tests are completed (or before starting next tests) and flyway just inserts two tags into this table every time you run the tests.
If that's right - you can just reset sequence in SQLite to set it back to 1 so next inserted row will be inserted with this id. You can do it by running the following query:
UPDATE `sqlite_sequence` SET `seq` = 1 WHERE `name` = 'tags_table_name';
Alternatively, you can set seq to 0 - this value is incorrect so SQLite will use next available correct value (if there are no rows in the table - it will be one, if there are some values - it will first available number).
Yet another possibility is just to delete your table after tests and recreate it before running next tests - as it is a database and table just for tests - it should work correctly. This way you have your sequence counter set back to value 1 each time. I would actually go this way until you have really good reason not to delete the table.
I have tried to install the Bugzilla-5.0.4 version in my Windows 10 OS system.
Also, I have installed MySQL 8.0 version along to maintain the all Bug data assets. I have installed all plugin which were not install.
I have provided all database configuration in localconfig file.
But i am facing issue while running checksetup.pl command .
Few last lines taken from the CMD window while executing below command.
c:\Bugzilla>perl checksetup.pl
* This is Bugzilla 5.0.4 on perl 5.24.3
* Running on Win10 Build 17134
Checking perl modules...
.
.
.
.
.
Checking for DBD-mysql (v4.001) ok: found v4.033
Checking for MySQL (v5.0.15) ok: found v8.0.15
Adding new table groups...
DBD::mysql::db do failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups (
id mediumint auto_increment PRIMARY KEY NOT NULL,
name varchar(255) N' at line 1 [for Statement "CREATE TABLE groups (
id mediumint auto_increment PRIMARY KEY NOT NULL,
name varchar(255) NOT NULL,
description mediumtext NOT NULL,
isbuggroup tinyint NOT NULL,
userregexp tinytext DEFAULT '' NOT NULL,
isactive tinyint DEFAULT 1 NOT NULL,
icon_url tinytext
) ENGINE = InnoDB CHARACTER SET utf8"] at Bugzilla/DB.pm line 837.
Bugzilla::DB::_bz_add_table_raw(Bugzilla::DB::Mysql=HASH(0x913ec90), "groups", HASH(0x94cf7c8)) called at Bugzilla/DB.pm line 796
Bugzilla::DB::bz_add_table(Bugzilla::DB::Mysql=HASH(0x913ec90), "groups", HASH(0x94cf7c8)) called at Bugzilla/DB.pm line 509
Bugzilla::DB::bz_setup_database(Bugzilla::DB::Mysql=HASH(0x913ec90)) called at Bugzilla/DB/Mysql.pm line 558
Bugzilla::DB::Mysql::bz_setup_database(Bugzilla::DB::Mysql=HASH(0x913ec90)) called at checksetup.pl line 121
I really appreciate your help.
Thank you.
Resolved.
The issue is mainly with current BugZilla 5.0.4 version. The scripts to generate the tables and all relevant asset in MySql 8.0 doesn't support UTF-8.
Thus i am looking for downgrading the MySQL version to 5x versions.
Below are external links for your reference.
https://bugzilla.mozilla.org/show_bug.cgi?id=1424043
https://groups.google.com/forum/#!topic/mozilla.community.india/LRwxmGJ2yNQ
I'm developing a website which, as of current, both has a production and a test database.
The production database is hosted externally while the test database is hosted locally.
Whenever I make changes to my database I apply the changes through a migration.
After having added a new migration I run the update-database command on both my production and test database to keep them in sync.
I applied the migration just fine to my production database, however, when I wanna apply the migration to my test database I see that it attempts to apply ALL the previous migrations (and not just the new one):
Here is the output:
Applying explicit migrations: [201603230047093_Initial,
201603232305269_AddedBlobNameToImage,
201603242121190_RemovedSourceFromRealestateDbTable,
201603311617077_AddedSourceUrlId,
201604012033331_AddedIndexProfileAndFacebookNotifications,
201604012233271_RemovedTenantIndexProfile,
201604042359214_AddRealestateFilter]. Applying explicit migration:
201603230047093_Initial. System.Data.SqlClient.SqlException
(0x80131904): There is already an object named 'Cities' in the
database.
Obviously it fails since the current state of the database is at the second latest migration. However I wonder why it attempts to apply ALL the previous migrations?
Unlike the production database (which has had all the migrations applied one at a time), the test database was deleted and created at the previous migration so its migration history table only contains one row:
201604012239054_InitialCreate
(I assume InitialCreate is an auto generated name of all the previous migrations combined).
In summary:
Why is the test database trying to apply ALL the previous migrations instead of just the newly added?
EDIT:
When running COMMMAND I get the follow output script:
DECLARE #CurrentMigration [nvarchar](max)
IF object_id('[dbo].[__MigrationHistory]') IS NOT NULL
SELECT #CurrentMigration =
(SELECT TOP (1)
[Project1].[MigrationId] AS [MigrationId]
FROM ( SELECT
[Extent1].[MigrationId] AS [MigrationId]
FROM [dbo].[__MigrationHistory] AS [Extent1]
WHERE [Extent1].[ContextKey] = N'Boligside.Migrations.Configuration'
) AS [Project1]
ORDER BY [Project1].[MigrationId] DESC)
IF #CurrentMigration IS NULL
SET #CurrentMigration = '0'
IF #CurrentMigration < '201603230047093_Initial'
(it proceeds making if statements for each previous migration)
The current migrations table in my database looks the following (note that the first row is for a logging framework so it's not related):
One issue that can cause migrations to rerun is if your context key changes which can happen during refactoring. There are a couple of ways to solve this:
1) Update the old records in __MigrationHistory with the new values:
UPDATE [dbo].[__MigrationHistory]
SET [ContextKey] = ‘New_Namespace.Migrations.Configuration’
WHERE [ContextKey] = ‘Old_Namespace.Migrations.Configuration’
2) You can hard code the old context key into the constructor of your migration Configuration class:
public Configuration()
{
AutomaticMigrationsEnabled = false;
this.ContextKey = “Old_Namespace.Migrations.Configuration”;
}
Here is a good article on how migrations run under the hood: https://msdn.microsoft.com/en-US/data/dn481501?f=255&MSPPError=-2147217396
See also http://jameschambers.com/2014/02/changing-the-namespace-with-entity-framework-6-0-code-first-databases/
I am using Django version 1.5.4 and I followed the instructions here
http://www.tangowithdjango.com/book/chapters/models.html
But I cannot find django_admin_log table.
I manually deleted rango.db from
C:\Users\Glowie\django\tango_with_django_project
The INSTALLED_APPS in settings.py looks like this
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'rango',
)
I executed the command
PS C:\users\Glowie\django\tango_with_django_project> python manage.py syncdb
Which outputs:
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table rango_category
Creating table rango_page
And then asks me to define a superuser, which I do each time .....
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no):
Which outputs
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
Then I run the command
PS C:\users\Glowie\django\tango_with_django_project> python manage.py sql rango
Which outputs
BEGIN;
CREATE TABLE "rango_category" (
"id" integer NOT NULL PRIMARY KEY,
"name" varchar(128) NOT NULL UNIQUE
)
;
CREATE TABLE "rango_page" (
"id" integer NOT NULL PRIMARY KEY,
"category_id" integer NOT NULL REFERENCES "rango_category" ("id"),
"title" varchar(128) NOT NULL,
"url" varchar(200) NOT NULL,
"views" integer NOT NULL
)
;
COMMIT;
But where is django_admin_log table. The text says
You should see that the table django_admin_log is created for you.
Once done, open your project’s urls.py file. This was created in the
project configuration directory.
Where will I find django_admin_log?
Please tell me where is "project configuration directory".
django_admin_log is a table that was created when you ran python manage.py syncdb. It's showing in the terminal output you posted that displayed after you ran syncdb:
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log <---RIGHT HERE
Creating table rango_category
Creating table rango_page
That table isn't really important to worry about now that it's actually created. The real key for you is to find your urls.py in your project configuration directory.
Your project configuration directory is a directory within your project directory that has the same name as your project directory. From earlier in the Tango with Django tutorial:
You’ll now notice within your workspace is a directory set to the name
of your new project, tango_with_django_project. Within this newly
created directory, you should see two items:
another directory with the same name as your project, tango_with_django_project; and
a Python script called manage.py.
For the purposes of this tutorial, we call this nested directory the
project configuration directory. Within this directory, you will find
four Python scripts. We will discuss this scripts in detail later on,
but for now you should see:
Thus, based on your directory structure, your project configuration directory is located at:
PS C:\users\Glowie\django\tango_with_django_project\tango_with_django_project>
and the tutorial wants you to open the urls.py file within that directory.