Change a filename migration with Flyway - database

I need to rename a Flyway migration file. I've already applied the migration on my local database.
How can I drop or reset my local postgres database to not have the Flyway migration exception?

If you want to drop the database, issue this command:
drop database testdb;
Then:
create database testdb;
If you don't want to go that far, and you want to bypass your server error, do this:
update schema_version set description = '', script = '', checksum = '' where version = '';
Then restart your server.

Related

Moving DataBase from Microsoft SQL folder to App_Data folder (appseting.json)

1. "WebApi": "Data Source=.;Initial Catalog=TaskDB; Integrated Security=true"
2. "WebApi": "Server=(localdb)\\mssqllocaldb;AttachDBFilename=%CONTENTROOTPATH%\\App_Data\\TaskDB.mdf;Trusted_Connection=true;MultipleActiveResultSets=true"
I am trying to move my DataBase from main folder of Microsoft SQL to project folder App_Data, but it does not work for some reason. I do not know why maybe my connection string is wrong. So with number 1 is working fine, but it is in main folder of Microsoft SQL, but with number 2 there is something wrong I guess
The files of database are exclusive in hand of SQL Server. You can not move database when it is online. Taking database offline, requires that no one be connected to database.
First take the database offline then try to move the files. You can take the database offline both using SSMS and query. First line of code kill all active sessions then set database multiple user; but it must be offline before anyone can connect to database so all these code must be executed together.
ALTER DATABASE DatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE DatabaseName SET MULTI_USER
GO
USE master
GO
ALTER DATABASE DATABASE_NAME SET OFFLINE
Be aware that when you move file to another location database could not been brought ONLINE if you do not set new filename before taking the database offline.
Use this code for all of files that you want to move them.
ALTER DATABASE TEST
MODIFY FILE (NAME = 'LOGICAL_NAME', FILENAME = 'New_Directort\Filename.mdf')
After you moved the files then bring online the database with this statement.
ALTER DATABASE DATABASE_NAME SET ONLINE
As you can see this action is not a kind, that can be done without plan. Specially with application code. When trying to do it in application code; then all session including application connection will be lost. then you can not continue the progress.

Retrieve SQL Server database from old Windows

I have just changed my Windows. In the old SQL Server, I had some important databases and I want to find and copy them to new installed windows and SQL Server.
How can I find and copy old databases from old windows and copy them to new SQL Server?
P.S: Actually, my I have changed my hard disk and all of the old files
is located on my old hard drive and I want to find and copy the old
server from old hard drive to new drive.
You can either backup the prior database or detach the database .mdf (data) and .ldf (log) file and reattach via http://blog.sqlauthority.com/2007/08/24/sql-server-2005-t-sql-script-to-attach-and-detach-database/
or
Backup your database and restore. Six of one, half dozen of the other.
-- Step 1 : Detach Database using following script
USE [master]
GO
EXEC MASTER.dbo.sp_detach_db #dbname = N'AdventureWorks',
#keepfulltextindexfile = N'true'
GO
-- Step 2 : Move Data files and Log files to new location
-- Do this step and move to Step 3
-- Step 3 : Attach Database using following script
USE [master]
GO
CREATE DATABASE [AdventureWorks] ON
( FILENAME = N'C:\Data\AdventureWorks_Data.mdf' ),
( FILENAME = N'C:\Data\AdventureWorks_Log.ldf' )
FOR ATTACH
GO
IF EXISTS ( SELECT name
FROM MASTER.sys.databases sd
WHERE name = N'AdventureWorks'
AND SUSER_SNAME(sd.owner_sid) = SUSER_SNAME() )
EXEC [AdventureWorks].dbo.sp_changedbowner #loginame=N'sa',
#map=false
GO
Create a Full Database Backup
There are other options as well (Red Gate tools, Visual Studio Tools, etc)
Make sure your database engine is running. Connect to your old server using SSMS (SQL Server Management Studio) and backup the database. Then transfer the backup file to the new system and restore the backup using SSMS again.

SQL Server backup to Azure stopped working after moving DB files

I have a database in SQL Server 2014 on premises. For that database I have a backup to Azure storage configured using smart_admin.sp_set_db_backup procedure.
Recently I had to move the database files from one disk to another. I detached database, moved files, reattached it.
After that my backup stopped working. The function smart_admin.fn_backup_db_config shows that database backup record exists but database marked as is_dropped = 1
Any attempt to enable or disable backup for this database fails with error:
SQL Server Managed Backup to Windows Azure cannot configure the database, 'DATABASE_NAME', because it either does not exist or is offline.
Any way I can remove backup configuration information and create a new one? One of the ideas I found is rename the database, but I cannot do that in production.
Vad's answer is close, but there can be more than one record in autoadmin_managed_databases for a given db_name. You need to get the last record, which is the one with the max autoadmin_id. I picked the wrong one, and SQL Server repopulated the drop_date after I ran smart_admin.sp_set_db_backup or the 15 minute interval ran.
use msdb;
go
update [dbo].[autoadmin_managed_databases]
set drop_date = null
where [autoadmin_id]= (select max(autoadmin_id)
from [dbo].[autoadmin_managed_databases]
where db_name = '<DROPPPED_DATABASE_NAME>')
go
Managed Backups - is_dropped flag set to Yes after detaching database
and reattaching DB
Rename the database and set up managed backup again.
Reference
As I mentioned earlier I was not allowed to rename the database on the Production. So I found where it's marked as dropped and changed the value. That helped. Automated backups for the database started working again. IMO what happened looks like a bug in SQL Server 2014.
use msdb;
go
update [dbo].[autoadmin_managed_databases]
set drop_date = null
where [db_name] = '<DROPPED_DATABASE_NAME>'
go

How do I change the maintenance database for Postgres?

I'm running PostgreSQL version 9.0 on OSX version 10.6.6. Somehow one of my development databases has become the maintenance db, not postgres (this db also exists). I can't find any documentation on how to change/set the maintenance db back to postgres.
I can't drop my development database because of this issue...
You can change maintenance db from pgAdmin but you have to be disconnected from the database engine to be able to do that.
First disconnect:
Then in the database server properties:
Choose the desired maintenance database:
You're not entirely clear on this, but do you mean the "Maintenance DB" selection in pgAdmin III?
Select the server in your "object browser" pane; right click -> Properties
The fifth field is "Maintenance DB"
Maintenance db field is read-only , you can't change it.So you should keep your server properties somewhere and create new server with these properties and set maintenance db "postgres". Now you are able to drop database.
The command line option is :
psql -U intelison -c "UPDATE pg_database SET datistemplate=false, datallowconn=true WHERE datname = '<your_database_name>'"

SQL Server - Enabling FileStream after a DB has been created

We have a database and have decided to enable it for FileStream use. I think I've done everything I'm supposed to except creating a FileStream Data Container. I can't seem to find a way to do this in SSMS 2008 on our existing database. Can this only be done at the time a database is created?
To add FS support to existing database just create a new filegroup, then add the fs file;
alter database YourDatabase
add filegroup fsGroup contains filestream;
go
alter database YourDatabase
add file
( NAME = 'fsYourDatabase', FILENAME = 'c:\<your_file_path>'
)
to filegroup fsGroup;
go
More here: BOL Link
And definitely read everything Paul Randal has written about filestream: link
From http://brianseekford.com/wordpress/?p=509
If you still get FILESTREAM feature is disabled. check the 'running values' of your server and you'll probably still see it is disabled even if you enabled it.
You can fix it by enabling filestream here too (under Sql configuration manager).
Then you need to run
EXEC sp_configure filestream_access_level, 2
RECONFIGURE

Resources