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

Integrate 3rd party Search Replace DB script #13

Open
alkah3st opened this issue Sep 4, 2013 · 29 comments
Open

Integrate 3rd party Search Replace DB script #13

alkah3st opened this issue Sep 4, 2013 · 29 comments
Assignees
Milestone

Comments

@alkah3st
Copy link

alkah3st commented Sep 4, 2013

Does the find/replace part of this task account for serialized data?

@getdave
Copy link
Owner

getdave commented Sep 20, 2013

Not at the moment. I'm planning on making use of a 3rd party script to integrate this. However pull requests are more than welcome.

@getdave
Copy link
Owner

getdave commented Nov 12, 2013

@alkah3st I've recently upped by knowledge of NPM. I now understand we can reference a Git repo as a dependency. Therefore I propose the following

  1. Define https://github.com/interconnectit/Search-Replace-DB as a dependency in package.json
  2. Replace the sed (or allow as fallback?) with searchreplacedb2cli.php CLI script to account for Serialized data. We can use exec to do this easily.

If you're experienced in Grunt/Node I'd welcome some help on this.

@ghost ghost assigned getdave Nov 12, 2013
@alkah3st
Copy link
Author

Sweet, searchreplacedb is exactly the script I use to do the find/replace. I'm not by any means a pro with Grunt/node but I'll see what I can do.

@getdave
Copy link
Owner

getdave commented Nov 18, 2013

Should be pretty simple. I'm planning to get to this Thurs/Fri

@getdave
Copy link
Owner

getdave commented Jan 3, 2014

@alkah3st if you're interested I've made some good progress on this at

https://github.com/getdave/grunt-deployments/tree/feature/advanced-search-replace

Requires a lot of testing however. Would you be able to give it a whirl and see if it works for you?

@alkah3st
Copy link
Author

alkah3st commented Jan 3, 2014

Awesome, I'll check it out this weekend. I just in fact was retooling my own website, so I can experiment on it there.

@getdave
Copy link
Owner

getdave commented Jan 3, 2014

That would be much appreciated. Be sure to do a fresh install. Dependencies have changed a lot. NPM update...

Cheers

@getdave
Copy link
Owner

getdave commented Jan 17, 2014

@alkah3st Just checking to see if you've had any chance to test this out?

@alkah3st
Copy link
Author

Hi Dave, sorry I have disappeared from the face of the earth these past two months. I've been settling into a new job. Quick question I have about your advanced search/replace deployments script: I have everything set up properly in my gruntfile, but what's not clear to me is steps 1) and 2) you described above:

  1. Define https://github.com/interconnectit/Search-Replace-DB as a dependency in package.json
  2. Replace the sed (or allow as fallback?) with searchreplacedb2cli.php CLI script to account for Serialized data. We can use exec to do this easily.

I understand I need to include a reference to searchreplacedb2 script in my package.json, but am I including the git path (i.e., https://github.com/interconnectit/Search-Replace-DB.git) in the package like so:

"grunt-deployments": "~0.2.0",
"https://github.com/interconnectit/Search-Replace-DB.git": ??

Also I'm not sure what you mean by #2.

@getdave
Copy link
Owner

getdave commented Feb 21, 2014

@alkah3st Not a problem.

I've actually already done most of the work on this branch

https://github.com/getdave/grunt-deployments/tree/feature/advanced-search-replace

Check out this branch and give it a whirl. I'm interested to see what issues you encounter.

@alkah3st
Copy link
Author

Ah cool, that's the one I'm testing out. I have an environment where I'll regularly be moving a WP site from dev -> stage -> live, so I think this would be an ideal test.

@getdave
Copy link
Owner

getdave commented Feb 24, 2014

@alkah3st I would be great if you could test this. Be careful with it as it's not production-ready code yet!

@alkah3st
Copy link
Author

Here's a question for you: so I have everything set up in my external file:

{
"local": {
"title": "Local",
"database": "xxx",
"user": "xxx",
"pass": "",
"host": "xxx",
"url": "xxx"
},
"develop": {
"title": "xxx",
"database": "xxx",
"user": "xxx",
"pass": "xxx",
"host": "xxx",
"url": "xxx",
"ssh_user": "xxx",
"ssh_host": "xxx",
"ssh_port": "xxx"
},
"stage": {
"title": "xxx",
"database": "xxx",
"user": "xxx",
"pass": "xxx",
"host": "xxx",
"url": "xxx",
"ssh_user": "xxx",
"ssh_host": "xxx",
"ssh_port": "xxx"
}
}

as .dbpass, and the task in my gruntfile is:

    deployments: {
        options: {
          backups_dir: 'db'
        },
        local: '<%= untracked_targets.local %>',
        develop: '<%= untracked_targets.develop %>',
        stage: '<%= untracked_targets.stage %>'
     },

When I run db_pull --src="local" --dest="develop" I get this error:

"Warning: An error occurred while processing a template (Cannot read property 'local' of undefined). Use --force to continue."

Is "untracked_targets" correct to reference the external file with the credentials?

@getdave
Copy link
Owner

getdave commented Feb 26, 2014

Thanks for giving this a shot. I've tried to help below...

Is "untracked_targets" correct to reference the external file with the credentials?

You can name and reference the external file however you'd like. A good explanation of how to achieve this is found on the readme. My file is similar to the below:

{
    "local": {
        "title": "Local",
        "database": "my_db_name",        
        "user": "my_db_user",
        "pass": "my_db_pass",
        "host": "localhost",  
        "url": "www.test.local"
    },
    "develop": {
        "title": "Development Server",
        "database": "my_db_name",        
        "user": "my_db_user",
        "pass": "my_db_pass",
        "host": "localhost",      
        "url": "www.mydevurl.com",
        "ssh_user": "my_ssh_user",
        "ssh_host": "111.111.11.11"  
    }
}

...and the portion of the my Gruntfile which references it is:

grunt.initConfig({
    db_fixture: grunt.file.readJSON('test/fixtures/basic_config.json'), // the path can be to any location where you'd like to store the config file
    deployments: {
        options: {
            backups_dir: ''
        },
        local: '<%= db_fixture.local %>', // make sure you've created valid fixture DB creds
        develop: '<%= db_fixture.develop %>' // make sure you've created valid fixture DB creds
    },

    // remainder of Gruntfile continues...

When I run db_pull --src="local" --dest="develop" I get this error:

In hindsight the use of db_pull as the CLI command is stupid. I would like to rename is to db_migrate. Feel free to do this via a pull request into the advanced search replace branch (or I'll do it later!).

"Warning: An error occurred while processing a template (Cannot read property 'local' of undefined). Use --force to continue."

This is because it cannot find a reference to "local". You will need to double check that the script has a "local" target. Hopefully it's just a minor typo rather than an issue with the script.

Happy to help you get this working. Sorry it's been less than smooth so far!

@alkah3st
Copy link
Author

Awesome, I will try this out once I get to the office!

@getdave
Copy link
Owner

getdave commented Mar 3, 2014

@alkah3st Did you have any luck?

@getdave
Copy link
Owner

getdave commented Mar 8, 2014

New Requirement

Now that the original SearchReplaceDB repo has been updated to include a package.json file this project should reference the original repo as a dependency rather than my forked version. This should be updated in package.json.

@alkah3st
Copy link
Author

Hi Dave, so I was diving back into this, but now it's not clear to me how I'm supposed to include the new version. My package.json references grunt-deployments:

{
  "name": "leap-wordpress-package",
  "version": "1.0.0",
  "dependencies": {},
  "devDependencies": {
   ...
    "grunt-deployments": "0.2.0"
  }
}

I'm including a config file as dbpass.json, and this is my gruntfile:

module.exports = function(grunt) {
    grunt.initConfig({
        dbcreds: grunt.file.readJSON('dbpass.json'),
        deployments: {
            options: {
              backups_dir: 'db'
            },
            local: '<%= dbcreds.local %>',
            develop: '<%= dbcreds.develop %>',
            stage: '<%= dbcreds.stage %>'
         }
    });
};

What am I missing here?

@getdave
Copy link
Owner

getdave commented Mar 24, 2014

Hmmm...that's a good point. Not sure of the top of my head how you'd reference a feature branch on Github via `package.json.

Might be easier to test the new Search & Replace branch in isolation from your leap-wordpress-package? Just checkout the branch and try it out...?

Sorry if this is making things difficult for you.

@davemac
Copy link

davemac commented Mar 30, 2014

Following these comments with interest, am I right in thinking the Search Replace DB feature branch hasn't been merged into the master as of yet?

@alkah3st
Copy link
Author

That's where I'm confused too... Not sure how to run this independently of the master.

@getdave
Copy link
Owner

getdave commented Mar 31, 2014

@davemac @alkah3st Sorry guys. Appreciate this is confusing.

The Search Replace DB is on a branch at:

https://github.com/getdave/grunt-deployments/tree/feature/advanced-search-replace

I would advise that you create a clean dir on your local machine and then clone a fresh copy of the repo. You can do this using

git clone -b feature/advanced-search-replace git@github.com:getdave/grunt-deployments.git

That should do it. From there you should be able to test the functionality.

Alternatively, if you already have a project setup which makes use of Grunt Deployments then I believe you can modify your package.json to refer to a branch directly

http://stackoverflow.com/questions/16350673/depend-on-a-branch-using-a-git-url-in-a-package-json

So you'd refer to the branch feature/advanced-search-replace

@getdave
Copy link
Owner

getdave commented Mar 31, 2014

Also I'm consider making this an optional feature. So the idea would be

  • Plugin defaults to using Search&ReplaceDB for search/replace
  • ...or you can pass an option to the task to tell it to use sed for search/replace instead
  • ...or you can pass your own function to do the search/replace manually.

Also note this task which relates to this quite well #41

@davemac
Copy link

davemac commented Mar 31, 2014

Thanks Dave, my vote would certainly be to make search replace db an optional feature. That would then make things easier for users, I suppose - but more work for you!

@davemac
Copy link

davemac commented May 8, 2014

OK have tried to add the advanced search replace feature branch to package.json:

"devDependencies": {
"grunt": "~0.4.2",
"grunt-autoprefixer": "~0.7.2",
"grunt-contrib-imagemin": "~0.6.0",
"grunt-contrib-jshint": "~0.9.2",
"grunt-contrib-uglify": "^0.4.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-rsync": "~0.5.0",
"matchdep": "~0.3.0",
"grunt-deployments": "git://github.com/getdave/grunt-deployments.git#feature/advanced-search-replace"
}

But am getting an error when I run npm update:

8397 error git fetch -a origin (git@github.com:getdave/Search-Replace-DB.git) Permission denied (publickey). 8397 error git fetch -a origin (git@github.com:getdave/Search-Replace-DB.git) fatal: Could not read from remote repository. 8397 error git fetch -a origin (git@github.com:getdave/Search-Replace-DB.git) 8397 error git fetch -a origin (git@github.com:getdave/Search-Replace-DB.git) Please make sure you have the correct access rights 8397 error git fetch -a origin (git@github.com:getdave/Search-Replace-DB.git) and the repository exists

@davemac
Copy link

davemac commented May 8, 2014

Worked it out, you need to delete node_modules and run npm install again.

After hours of googling, I found an explanation here http://howtonode.org/managing-module-dependencies

@getdave
Copy link
Owner

getdave commented May 9, 2014

@davemac Nice work sir!

@getdave
Copy link
Owner

getdave commented May 11, 2014

@davemac If it's possible to advise on your progress with testing this. Has it worked for you? Any major errors? Any suggested improvements. As always pull requests into the correct branch are welcome.

I'd really like to get this released so I'm really appreciative of your testing efforts!

@davemac
Copy link

davemac commented May 12, 2014

See issue #43 which helps with getting this feature branch installed as a dependency and also #44 which I believe is an outstanding issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants