-
Notifications
You must be signed in to change notification settings - Fork 70
Rename post table to program #1607
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
Merged
david-yz-liu
merged 15 commits into
Courseography:master
from
akarki2005:rename-post-table-to-program
Nov 13, 2025
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4343e5f
added migration script
akarki2005 6b62f4c
added cli option for database migration
akarki2005 db10ee1
updated hard-coded schema and all dependent modules
akarki2005 3a0fb3b
fixed tests
akarki2005 d3b4e2d
updated changelog/readme, removed migration logic from database-setup
akarki2005 0947ff2
reverted database-setup changes
akarki2005 2ff915f
completed migration script
akarki2005 e807a7a
fixed some lingering naming issues in ProgramControllerTests.hs
akarki2005 a49e6f3
incorporated feedback and made sure applyMigrations updates version n…
akarki2005 f592ede
fixed linting issue
akarki2005 b27d996
continuation of last fix
akarki2005 836cc4d
Merge branch 'master' of https://github.com/Courseography/courseograp…
akarki2005 8adedd1
Merge branch 'master' of https://github.com/Courseography/courseograp…
akarki2005 edc88f5
implemented feedback and moved some functions around to fix circular …
akarki2005 c92864a
Merge branch 'master' into rename-post-table-to-program
david-yz-liu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| module Database.Migrations | ||
| (migrateDatabase) where | ||
|
|
||
| import Control.Monad.Reader (MonadIO) | ||
| import Data.List (sortOn) | ||
| import Database.Database (getDatabaseVersion, setDatabaseVersion) | ||
| import Database.Persist.Sql (Migration, SqlPersistT, addMigration, runMigrationUnsafe) | ||
|
|
||
| data MigrationWrapper = MigrationWrapper { | ||
| version :: Int, | ||
| script :: Migration | ||
| } | ||
|
|
||
| -- | Migrates the database | ||
| migrateDatabase :: MonadIO m => SqlPersistT m () | ||
| migrateDatabase = do | ||
| currVersion <- getDatabaseVersion | ||
| applyMigrations currVersion migrationList | ||
|
|
||
| -- | Migrates the database by applying only migrations newer than the current version number | ||
| applyMigrations :: MonadIO m => Int -> [MigrationWrapper] -> SqlPersistT m () | ||
| applyMigrations currVersion migrations = do | ||
| mapM_ (runMigrationUnsafe . script) | ||
| $ sortOn version | ||
| $ filter (\migration -> version migration > currVersion) migrations | ||
|
|
||
| case migrations of | ||
| [] -> return () | ||
| _ -> setDatabaseVersion $ maximum $ map version migrations | ||
|
|
||
| -- | List of migrations | ||
| migrationList :: [MigrationWrapper] | ||
| migrationList = [MigrationWrapper {version=2, script=renamePostTables}] | ||
|
|
||
| -- | Migration script which renames the Post tables to Program | ||
| renamePostTables :: Migration | ||
| renamePostTables = do | ||
| addMigration True "ALTER TABLE post RENAME TO program;" | ||
| addMigration True "ALTER TABLE post_category RENAME TO program_category;" | ||
| addMigration True "ALTER TABLE program_category RENAME COLUMN post TO program;" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.