Restructure spec database logic.

[25587]