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

No error when removing field from data structure without migration #65

Open
lippling opened this issue Nov 5, 2015 · 1 comment
Open

Comments

@lippling
Copy link

lippling commented Nov 5, 2015

Hi,

I have the following code:

data File = File {
    fileName     :: String
  , filePath     :: FilePath
  , fileContents :: ByteString
}
$(deriveSafeCopy 0 'base ''File)

data Database = Database [File]
$(deriveSafeCopy 0 'base ''Database)

addFile :: File -> Update Database ()
addFile file = do
    Database files <- get
    put $ Database (file:files)

viewFiles :: Int -> Query Database [File]
viewFiles limit = do
    Database files <- ask
    return $ take limit files

$(makeAcidic ''Database ['addFile, 'viewFiles]) 

I did some tests and in one test I removed the fileName field. Then I ran a ViewFiles 10 query and no error showed up, but the resulting data was incorrect.

For example:
I inserted File "a" "b" "c" and after removing the field I got Field "a" "\NUL" back.

It was also possible to add new Files to the state. The new Files were ok when retrieved by a query. (A migration solved the problem too, of course).

Is this behavior intentional or a bug? I would expect an error, because the structure doesn't match the persisted structure.

@stepcut
Copy link
Member

stepcut commented May 31, 2016

This is a limitation of the way SafeCopy is currently implemented. It is expected behavior -- but an error would be better. The short answer is "don't do that". The long answer is that it would be nice (for a variety of reasons) if acid-state/safecopy could produce a schema for the .log files.

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

No branches or pull requests

2 participants