4

i have a php app on Heroku where the user data is stored in sqlite. Every time i update my php files and push it to Heroku, the local sqlite file is also updated...meaning that i lose the working data and get the startup data.

including the file in .gitignore makes sure that this file is not available to the Heroku app. it simply deletes the file from the remote git repository.

git update-index --assume-unchanged fails to mark the sqlite file. it gives me an error saying "unable to mark file".

Need help with having the sqlite file created once and then not updated/deleted at all. Thanx for the suggestions.

4

3 回答 3

1

Adding file mask to .gitignore does not do anything by itself, and certainly does NOT delete file from remote repository (read more here).

In general, it is really bad idea to store SQLite databases under source control (including git). Best solution for this is to create script that creates template database if necessary. This script can look like this:

database.sql:

BEGIN TRANSACTION; -- wrap everything into one transaction
-- create tables, always use NOT EXISTS:
CREATE TABLE IF NOT EXISTS items (
    item_id INTEGER AUTOINCREMENT PRIMARY KEY,
    item_name VARCHAR(32)
);
-- create indexes, always use NOT EXISTS:
CREATE INDEX IF NOT EXISTS items_item_name ON items (item_name);
-- add more CREATE TABLE and/or CREATE INDEX statements... 

COMMIT;

Then you can execute this script using following command:

sqlite3 -init database.sql database.db ""

If you execute it first time, database.db would be created if it did not exist. If you execute it second time, nothing will happen. But, you can decide later to add more indexes or tables into your database.sql (which would be under source control), and executing it later would add missing objects into your database.

于 2013-09-22T07:05:34.953 回答
0
Edit .gitignore to match the file you want to ignore
git rm --cached /path/to/file

See here: Applying .gitignore to committed files

于 2013-09-21T17:19:31.967 回答
0

Ok.... seems i was over doing it. I should have had either the .gitignore entry or the --assume-unchanged. Both together some how messed up all settings. Currently removed the .gitignore entry and have set the sqlite file to be marked as unchanged until further notice, using git update-index --assume-unchanged myDB.sqlite This did the trick for me. @rkp & @mvp...thanks for the help ... no amount of help is good if i am over zealous! :)

于 2013-09-22T13:14:36.593 回答